DataFrame eltypes error without using eltypes

Hello All

I am trying to run Julia code on a Linux cluster that works flawlessly on my personal machine. The MWE that fails for me:

using Pkg
Pkg.activate("/home/path/JuliaEnv/") #Activate Environment
using DataFrames
println("BeginTest")
dummyDF = DataFrame([String],["String"],1)
println("EndTest")

fails with:

Activating environment at `~/path/JuliaEnv/Project.toml`
ERROR: LoadError: ArgumentError: `DataFrame` constructor with passed eltypes is not supported. Pass explicitly created columns to a `DataFrame` constructor instead.
Stacktrace:
[1] DataFrame(::Array{DataType,1}, ::Array{String,1}, ::Int64; makeunique::Bool) at path/.julia/packages/DataFrames/nxjiD/src/dataframe/dataframe.jl:380
[2] DataFrame(::Array{DataType,1}, ::Array{String,1}, ::Int64) at path/.julia/packages/DataFrames/nxjiD/src/dataframe/dataframe.jl:380
[3] top-level scope at file.jl:7
in expression starting at file.jl:7
BeginTest

I am not even using the eltypes command here and it fails. Ironically, the full script uses DataFrame(XLSX.readtable("ExcelFile.xlsx", "Sheet1"; infer_eltypes=true)...) at some previous stage without any problems, but it somehow fails to construct any DataFrames (which I need). This is on Julia 1.5.4, which I have reinstalled, I also tried 1.6.1, deleting various folders in Julia, recompiling, reinstating the environment etc, nothing worked.

Any help on how to resolve this is much appreciated, I don’t want to rewrite everything in Python just so I can use the cluster…

I forget which constructors are supported in which version of DataFrames, but this looks to me like the versions of DataFrames on the cluster and your personnel machine are different?

2 Likes

Indeed DataFrame([Int, Int], [:a, :b]) or similar (first a list of types, then a list of names) was removed in recent versions. Instead you can do DataFrame(a=Int[], b=Int[]), or if the names and types are variables you can do something like DataFrame(colnames .=> [type[] for type in types]).

Can you give the code at line 7 of file.jl?

1 Like

Ah yes - I think the error message is misleading, but indeed this way of constructing DataFrames seems to not be supported with this DataFrames version.

Yes using this construction method did the trick - line 7 is actually the DataFrame([String],[“String”],1) line from the MWE, but I omitted some commented out lines causing the discrepency between error message and MWE.