Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.
This repository was archived by the owner on May 21, 2022. It is now read-only.

eachtarget for dabeled data as stated in documentation #47

Closed
@racinmat

Description

@racinmat

Hi, I have MLDataPattern.jl v0.5.2, and DataFrames.jl v0.20.2, and I'm trying to reproduce the code in documentation: https://mldatapatternjl.readthedocs.io/en/latest/documentation/targets.html#example-2-symbol-support-for-dataframes-jl
I added

using DataFrames, LearnBase
LearnBase.getobs(df::DataFrame, idx) = df[idx,:]
LearnBase.nobs(df::DataFrame) = nrow(df)

but following code is not working for me, should I add some other method for DataFrames, or is there something else that needs to be done to get this working?

using DataFrames
df = DataFrame(x1 = rand(5), x2 = rand(5), y = [:a,:a,:b,:a,:b])
iter = eachtarget(row->row[1,:y], df)
julia> collect(iter)
ERROR: MethodError: no method matching getindex(::DataFrameRow{DataFrame,DataFrames.Index}, ::Int64, ::Symbol)
Closest candidates are:
  getindex(::DataFrameRow, ::Union{Signed, Symbol, Unsigned}) at C:\Users\racinsky\.julia\packages\DataFrames\S3ZFo\src\dataframerow\dataframerow.jl:94   
  getindex(::DataFrameRow, ::Union{Regex, AbstractArray{T,1} where T, All, Between, InvertedIndex}) at C:\Users\racinsky\.julia\packages\DataFrames\S3ZFo\src\dataframerow\dataframerow.jl:96
  getindex(::DataFrameRow, ::Colon) at C:\Users\racinsky\.julia\packages\DataFrames\S3ZFo\src\dataframerow\dataframerow.jl:98
Stacktrace:
 [1] (::var"#74#75")(::DataFrameRow{DataFrame,DataFrames.Index}) at C:\Projects\SampleLoaders.jl\test\runtests.jl:239
 [2] gettarget at C:\Users\racinsky\.julia\packages\MLDataPattern\nA4s5\src\targets.jl:151 [inlined]
 [3] _gettarget at C:\Users\racinsky\.julia\packages\MLDataPattern\nA4s5\src\targets.jl:144 [inlined]
 [4] (::MLDataPattern.var"#126#127"{var"#74#75"})(::DataSubset{DataFrame,Int64,LearnBase.ObsDim.Undefined}) at .\none:0
 [5] iterate at .\generator.jl:47 [inlined]
 [6] collect(::Base.Generator{ObsView{DataSubset{DataFrame,Int64,LearnBase.ObsDim.Undefined},DataFrame,LearnBase.ObsDim.Undefined},MLDataPattern.var"#126#127"{var"#74#75"}}) at .\array.jl:665
 [7] top-level scope at none:0

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions