# How to wrap DataFrame \[\] operator?

**URL:** <https://discourse.julialang.org/t/how-to-wrap-dataframe-operator/5267>\
**Category:** Data\
**Tags:** data\
**Created:** [August 7, 2017, 8:39pm UTC](https://discourse.julialang.org/t/how-to-wrap-dataframe-operator/5267 "2017-08-07T20:39:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 7, 2017, 8:39pm UTC](https://discourse.julialang.org/t/how-to-wrap-dataframe-operator/5267/1 "2017-08-07T20:39:44Z")

</div>

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

```julia
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`?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 7, 2017, 8:52pm UTC](https://discourse.julialang.org/t/how-to-wrap-dataframe-operator/5267/2 "2017-08-07T20:52:57Z")

</div>

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