Can DataFrames be distinguished by type?

I would like to have a function call fail or not depending on the type of a DataFrame. I cannot distinguish the DataFrames by column types or size.

For example, I would have two identical functions except for the argument type.

function foo1(df::DataFrame)
return nrow(df)

Here T is some other type, but with the same methods as a DataFrame

function foo2(df::T) 
return nrow(df)

Then I would create a standard dataframe and use it as an argument for foo.

df1 = DataFrame(:A => [1])

foo2 would fail, not because nrow is not a method, but because df1 is of the wrong type

I guess this could be done with the package TypedDelegation.jl but I wonder if there is a simpler way.

function foo2(df :: DataFrame)
    throw(ArgumentError("foo2 do not support arguments of type DataFrame"))
1 Like