Problem initializing dataframe column types

I’m having trouble initializing an empty dataframe intended to hold integer and floating point values:

julia> using DataFrames

julia> df = DataFrame([Int[],Float64[]], :auto)
0×2 DataFrame

julia> push!(df,Any[1,10.0])
1×2 DataFrame
 Row │ x1       x2
     │ Float64  Float64
─────┼──────────────────
   1 │     1.0     10.0

Why is the first column a Float64 rather than an Int? I’m using DataFrames version 1.2.1 with Julia 1.6.2.

Not sure why it behaves like that in this case and if it is intended. But as a quick workaround, if you can assign column names and do:

using DataFrames
df = DataFrame(a = Int64[], b = Float64[])
push!(df,[1,10.0])

then the types are as expected.

This isn’t about DataFrames, but rather auto-promotion. It looks like Julia promotes the Int[] to Float64[] when you make that array. Try adding an Any

julia> [Int[],Float64[]]
2-element Vector{Vector{Float64}}:
 []
 []

julia> Any[Int[],Float64[]]
2-element Vector{Any}:
 Int64[]
 Float64[]
4 Likes

Thanks!

Thanks for your solution as well!

Yes, this is what @pdeffebach suggested, which I marked as the answer.

Sorry, got code and error messages messed up here. Will delete post.