Hi,
I have a function on a DataFrame which should behave differently depending on the names / eltypes of the DataFrame columns. Is this possible using a multiple-dispatch like pattern?
Example:
using DataFrames
function myfunc(df:: AbstractDataFrame) # call this method if columns a + b exist and are numeric
df[!, :c] = df.a .* df.b
return df
end
function myfunc(df:: AbstractDataFrame) # call this method if columns a + c exist and are numeric
df[!, :b] = df.c ./ df.a
return df
end
foo = DataFrame(a=1:4, b=2:5)
bar = DataFrame(a=1:4, c=3:6)
myfunc(foo) # should call 1st definition
myfunc(bar) # should call 2nd definition
It would be possible to check the column names and eltypes inside the function, but I wonder if there is a more elegant / “Julian” way of doing this.