Getindex for Wrapper Type

I was implementing a wrapper type around a data frame, and was attempting to add getindex functionality so I didn’t have to manually access the frame and could just index into the wrapper type as in the code below.

using DataFrames

struct DiscreteDist
    table::DataFrame
end

getindex(x::DiscreteDist, i, j)=(x.table)[i,j]
example = DiscreteDist(DataFrame(A=[1,1,1,1]))

example[2,:A]

However, when I run this code it says that there’s no method matching getindex(::DiscreteDist, ::Int64, ::Symbol) even though I think my defined method covers those types.

Where have I gone wrong? Also, for future reference is there any better way to get the functionality of the type I’m trying to wrap accessible from the wrapper itself? Sorry if this is obvious, I’m still getting the hang of things.

To extend the existing function you need to use Base.getindex(x::DiscreteDist, i, j)=(x.table)[i,j], once I make that change your example works.

Thank you very much. Works like a charm.