Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguity error between CategoricalArrays and SentinelArrays #2883

Closed
JackDunnNZ opened this issue Sep 16, 2021 · 2 comments
Closed

Ambiguity error between CategoricalArrays and SentinelArrays #2883

JackDunnNZ opened this issue Sep 16, 2021 · 2 comments

Comments

@JackDunnNZ
Copy link

(Apologies that this isn't strictly related to DataFrames, but I'm not sure where the fix for this needs to be)

The following code works for me when using a single thread:

using CSV, DataFrames, CategoricalArrays
data = CSV.read("kc_house_data.csv", DataFrame)
select(data, :waterfront => categorical)

But if I run with multiple threads, it uses SentinelArrays when reading in the CSV and I get the following method ambiguity error between CategoricalArrays and SentinelArrays during the transform:

ERROR: MethodError: copyto!(::CategoricalVector{Int64, UInt32, Int64, CategoricalValue{Int64, UInt32}, Union{}}, ::SentinelArrays.ChainedVector{Int64, Vector{Int64}}) is ambiguous. Candidates:
  copyto!(dest::Union{SubArray{var"#s5", N, var"#s4", I, L} where {var"#s5", var"#s4"<:(CategoricalArray{T, var"#s3", R, V, C, U} where {var"#s3", V, C, U}), I, L}, CategoricalArray{T, N, R, V, C, U} where {V, C, U}} where {T, N, R<:Integer}, src::AbstractArray) in CategoricalArrays at /Users/jack/.julia/packages/CategoricalArrays/rDwMt/src/array.jl:615
  copyto!(dest::AbstractVector{T} where T, src::SentinelArrays.ChainedVector) in SentinelArrays at /Users/jack/.julia/packages/SentinelArrays/VbnBp/src/chainedvector.jl:335
Possible fix, define
  copyto!(::Union{SubArray{T, 1, var"#s4", I, L} where {T, T1, R<:Integer, var"#s4"<:(CategoricalArray{T1, var"#s3", R, V, C, U} where {var"#s3", V, C, U}), I, L}, CategoricalVector{T, R, V, C, U} where {C, U, T, R<:Integer, V}}, ::SentinelArrays.ChainedVector)
Stacktrace:
  [1] _convert(::Type{CategoricalVector{Int64, UInt32, V, C, U} where {V, C, U}}, A::SentinelArrays.ChainedVector{Int64, Vector{Int64}}; levels::Nothing)
    @ CategoricalArrays ~/.julia/packages/CategoricalArrays/rDwMt/src/array.jl:343
  [2] (CategoricalVector{Int64, UInt32, V, C, U} where {V, C, U})(A::SentinelArrays.ChainedVector{Int64, Vector{Int64}}; levels::Nothing, ordered::Bool)
    @ CategoricalArrays ~/.julia/packages/CategoricalArrays/rDwMt/src/array.jl:253
  [3] #categorical#72
    @ ~/.julia/packages/CategoricalArrays/rDwMt/src/array.jl:927 [inlined]
  [4] categorical(A::SentinelArrays.ChainedVector{Int64, Vector{Int64}})
    @ CategoricalArrays ~/.julia/packages/CategoricalArrays/rDwMt/src/array.jl:926
  [5] _transformation_helper(df::DataFrame, col_idx::Int64, ::Base.RefValue{Any})
    @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:368
  [6] select_transform!(::Base.RefValue{Any}, df::DataFrame, newdf::DataFrame, transformed_cols::Set{Symbol}, copycols::Bool, allow_resizing_newdf::Base.RefValue{Bool})
    @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:546
  [7] _manipulate(df::DataFrame, normalized_cs::Vector{Any}, copycols::Bool, keeprows::Bool)
    @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:1383
  [8] manipulate(df::DataFrame, cs::Any; copycols::Bool, keeprows::Bool, renamecols::Bool)
    @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:1311
  [9] select(df::DataFrame, args::Any; copycols::Bool, renamecols::Bool)
    @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:940
 [10] select(df::DataFrame, args::Any)
    @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:940
 [11] top-level scope
    @ REPL[3]:1

If helpful, the data is available here: kc_house_data.csv

All packages are up to date (CSV 0.9.3, DataFrames 1.2.2, CategoricalArrays 0.10.0, Sentinel Arrays 1.3.7)

@bkamins
Copy link
Member

bkamins commented Sep 16, 2021

Thank you for an excellent issue report. This is a known problem. It is tracked here JuliaData/CategoricalArrays.jl#361 (and it is good that you reported it so that we will get back to fixing it)

@JackDunnNZ
Copy link
Author

Thank you @bkamins, glad to hear you are all on top of it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants