You need to import index from DataFrames. That's one reason I prefer using
`using DataFrames` and defining methods with `DataFrames.index() = ...`.

On Fri, Mar 27, 2015 at 2:46 PM, <[email protected]> wrote:

> Ok, I narrowed it down to a very small test case.  The mymodule.jl file is
> at the bottom of this posting.  If you save that to a file then run this
> code, you'll get the same effect as my original problem except with the
> 'index' method.
>
> using mymodule
>
> mydf = MyDataFrame(Any[], Index())
>
> # This line complains that `index` has no method matching
> index(::MyDataFrame)
> display(mydf)
>
> # This displays my `index` method
> methods(index)
>
> # This shows that my `index` method works
> index(mydf)
>
>
> === mymodule.jl ===
>
> module mymodule
>
> import DataFrames: AbstractDataFrame, DataFrame, Index, nrow, ncol
> import DataArrays: DataArray
>
> export MyDataFrame, nrow, ncol, Index, index, columns
>
> type MyDataFrame <: AbstractDataFrame
>    columns::Vector{Any}
>    colindex::Index
>
>    function MyDataFrame(columns::Vector{Any}, colindex::Index)
>
>       ncols = length(columns)
>       if ncols > 1
>           nrows = length(columns[1])
>           equallengths = true
>           for i in 2:ncols
>               equallengths &= length(columns[i]) == nrows
>           end
>           if !equallengths
>               msg = "All columns in a DataFrame must be the same length"
>               throw(ArgumentError(msg))
>           end
>       end
>
>       if length(colindex) != ncols
>           msg = "Columns and column index must be the same length"
>           throw(ArgumentError(msg))
>       end
>
>       new(columns, colindex)
>    end
>
> end
>
> index(df::MyDataFrame) = df.colindex
> columns(df::MyDataFrame) = df.columns
>
> nrow(df::MyDataFrame) = ncol(df) > 0 ? length(df.columns[1])::Int : 0
> ncol(df::MyDataFrame) = length(index(df))
>
> end
>
> ==================
>

Reply via email to