Hi all,
I am using DataFrames
and wanting to specify intra-row constraints in YAML, which can then be parsed and applied to each row of the data.
As an example, the following code works:
d = DataFrame(
id = UInt.([1,2,3]),
dob=Date.(["1992-10-01", "1988-03-23", "1983-11-18"]),
date_of_marriage=[Date("2015-09-13"), missing, Date("1981-11-01")]
)
s = "(r) -> r[:date_of_marriage] > r[:dob]" # Constraint. To be loaded from a YAML file.
f = eval(parse(s))
for r in eachrow(d)
result = f(r)
ismissing(result) && continue # f returns missing
result && continue # f returns true
println(r)
end
However, when I include the same code in a function it fails. That is, this code:
function myfunc()
d = DataFrame(
id = UInt.([1,2,3]),
dob=Date.(["1992-10-01", "1988-03-23", "1983-11-18"]),
date_of_marriage=[Date("2015-09-13"), missing, Date("1981-11-01")]
)
s = "(r) -> r[:date_of_marriage] > r[:dob]"
f = eval(parse(s))
for r in eachrow(d)
result = f(r)
ismissing(result) && continue # f returns missing
result && continue # f returns true
println(r)
end
end
…has the following error:
ERROR: MethodError: no method matching (::##1#2)(::DataFrames.DataFrameRow{DataFrames.DataFrame}) The applicable method may be too new: running in world age 21858, while current world is 21859.
I have read past discussions of the world age problem but I must admit I just don’t get it. Can someone please explain the problem with the example above?
Also, tips welcome on the above implementation. Ideally I’d prefer to parse :date_of_marriage > :dob
instead of r[:date_of_marriage] > r[:dob]
, but my metaprogramming skills are pretty much non-existent.
Thanks,
Jock