2nd UPDATE: Confirmed as a bug by user @Matt B. See his answer below for more detail.
UPDATE: @waTeim has demonstrated that one can write and read a DataFrame that contains a column of type date (confirmed on my setup). This is important, as it means Julia can write and read some composite types that are in the column of a data-frame. However, the case of a type datetime (which is different to type date) still throws an error, so at this point the question remains unanswered.
In Julia, using the HDF5 and JLD package, it is possible to save and load DataFrames in a .jld file using, for example:
#Preamble
using HDF, JLD, DataFrames
filePath = "/home/colin/Test.jld";
#Save the data-frame
fid1 = jldopen(FP, "w");
write(fid1, "MyDataFrame", MyDataFrame);
close(fid1);
#Come back later and load the data-frame
fid1 = jldopen(FP, "r");
X = read(fid1, "MyDataFrame");
close(fid1);
This works nicely, as long as the columns of the data-frame are all vectors of a base Julia type like Float64
or Int64
. However, in practice, we will often want the first column of a data-frame to be a datetime
, which is not a base type (although might become one in future releases). In this situation, the code above fails for me on the read
operation, with a long error message (I'll add it to the bottom if anyone asks in the comments). Following the documentation for the JLD package, I tried the following when saving:
#Save the data-frame
fid1 = jldopen(FP, "w");
addrequire(fid1, "/home/colin/.julia/v0.2/DataFrames/src/dataframe.jl")
addrequire(fid1, "/home/colin/.julia/v0.2/Datetime/src/Datetime.jl")
write(fid1, "MyDataFrame", MyDataFrame);
close(fid1);
but this did not help.
Am I doing something stupid, or is this functionality simply not available?
Note: HDF5 tag included because the JLD package uses it.
serialize()
anddeserialize()
can probably be made to work, but the solution is not feasible in the long term since a different version of Julia or even an instance of Julia running on a different system may not read back the same data that was written. Thanks for the idea though, and sorry it has taken me so long to respond. – Colin T BowersPkg.checkout("HDF5")
to get this patch). – mbauman