How to wrap DataFrame [] operator?

I have a type that wraps a AbstractDataFrame, and I am interested in defining a method that just forwards the [] operator:

struct GeoData{DF<:AbstractDataFrame}
  data::DF
  coordnames::Vector{Symbol}
end

How to make code like geodata[[:colname1,:colname2]] work and return a GeoData object where the underlying data field is filtered to contain :colname1, :colname2 and the columns saved in coordnames?

The syntax a[b] operator just calls Base.getindex(a, b), so you just have to implement Base.getindex(a::GeoData, b)

1 Like