On Fri, 2015-03-27 at 19:46, [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)

This line is not valid syntax:

julia> # This line complains that `index` has no method matching 
       index(::MyDataFrame)
ERROR: syntax: invalid "::" syntax

So, correcting this everything seems to work, right?

> 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