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

Indexing error with Union{Float64,Missing} variables #23

Open
randyzwitch opened this issue Apr 9, 2018 · 2 comments
Open

Indexing error with Union{Float64,Missing} variables #23

randyzwitch opened this issue Apr 9, 2018 · 2 comments

Comments

@randyzwitch
Copy link

Given the dataframe described below, freqtable will fail. Switching the type from Union{Float64, Missings.Missing} to just Float64 allows the function to work

julia> showcols(storedf)
2080×10 DataFrames.DataFrame
│ Col # │ Name     │ Eltype                                                               │ Missing │ Values        │
├───────┼──────────┼──────────────────────────────────────────────────────────────────────┼─────────┼───────────────┤
│ 1     │ storeNum │ Union{Int64, Missings.Missing}                                       │ 0       │ 101  …  120   │
│ 2     │ Year     │ Union{Int64, Missings.Missing}                                       │ 0       │ 1  …  2       │
│ 3     │ Week     │ Union{Int64, Missings.Missing}                                       │ 0       │ 1  …  52      │
│ 4     │ p1sales  │ Union{Int64, Missings.Missing}                                       │ 0       │ 127  …  136   │
│ 5     │ p2sales  │ Union{Int64, Missings.Missing}                                       │ 0       │ 106  …  99    │
│ 6     │ p1price  │ Union{Float64, Missings.Missing}                                     │ 0       │ 2.29  …  2.49 │
│ 7     │ p2price  │ Union{Float64, Missings.Missing}                                     │ 0       │ 2.29  …  2.49 │
│ 8     │ p1prom   │ Union{Int64, Missings.Missing}                                       │ 0       │ 0  …  0       │
│ 9     │ p2prom   │ Union{Int64, Missings.Missing}                                       │ 0       │ 0  …  0       │
│ 10    │ country  │ Union{CategoricalArrays.CategoricalString{UInt32}, Missings.Missing} │ 0       │ US  …  CN     │
julia> using FreqTables

julia> freqtable(storedf, :p1price)
ERROR: ArgumentError: invalid index: 2.99
Stacktrace:
 [1] setindex!(::NamedArrays.NamedArray{Int64,1,Array{Int64,1},Tuple{DataStructures.OrderedDict{Union{Float64, Missings.Missing},Int64}}}, ::Int64, ::Float64) at /Users/randyzwitch/.julia/v0.6/NamedArrays/src/index.jl:134
 [2] _freqtable(::Tuple{Array{Union{Float64, Missings.Missing},1}}, ::Bool, ::FreqTables.UnitWeights, ::Void) at /Users/randyzwitch/.julia/v0.6/FreqTables/src/freqtable.jl:79
 [3] freqtable(::Array{Union{Float64, Missings.Missing},1}) at /Users/randyzwitch/.julia/v0.6/FreqTables/src/freqtable.jl:88
 [4] #freqtable#21(::Array{Any,1}, ::Function, ::DataFrames.DataFrame, ::Symbol, ::Vararg{Symbol,N} where N) at /Users/randyzwitch/.julia/v0.6/FreqTables/src/freqtable.jl:148
 [5] freqtable(::DataFrames.DataFrame, ::Symbol, ::Vararg{Symbol,N} where N) at /Users/randyzwitch/.julia/v0.6/FreqTables/src/freqtable.jl:148
@nalimilan
Copy link
Owner

Good catch, that's a bug in NamedArrays: davidavdav/NamedArrays.jl#62.

@nalimilan nalimilan changed the title Support Missings Indexing error with Union{Float64,Missing} variables Apr 10, 2018
@mirestrepo
Copy link

I run into the same issue with Union{Int64, Missings.Missing} and works if I convert to Int64

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

3 participants