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

Error "type Dict has no field" #352

Open
jariji opened this issue Dec 29, 2023 · 1 comment
Open

Error "type Dict has no field" #352

jariji opened this issue Dec 29, 2023 · 1 comment

Comments

@jariji
Copy link

jariji commented Dec 29, 2023

julia> DataFrame([Dict("a" => 1), Dict()])
ERROR: type Dict has no field a
Stacktrace:
  [1-10]  internal
       @ Base, Tables, DataFrames, Unknown
    [11] DataFrame(x::Vector{Dict})
       @ DataFrames ~/.julia/packages/DataFrames/58MUJ/src/other/tables.jl:48
Use `err` to retrieve the full stack trace.

julia> DataFrame([Dict("a" => 1), Dict("a" => 2)])
2×1 DataFrame
 Row │ a     
     │ Int64 
─────┼───────
   11
   22

I think this error message isn't that clear. Perhaps better:

Dict at index 2 has no key "a".

@bkamins bkamins transferred this issue from JuliaData/DataFrames.jl Dec 29, 2023
@bkamins
Copy link
Member

bkamins commented Dec 29, 2023

I am transferring it to Tables.jl as the issue is with column building mechanism that is implemented there:

julia> DataFrame([Dict("a" => 1), Dict()])
ERROR: type Dict has no field a
Stacktrace:
  [1] getproperty
    @ Base .\Base.jl:37 [inlined]
  [2] getcolumn(x::Dict{Any, Any}, nm::Symbol)
    @ Tables ~\.julia\packages\Tables\NSGZI\src\Tables.jl:102
  [3] getcolumn
    @ Tables ~\.julia\packages\Tables\NSGZI\src\tofromdatavalues.jl:73 [inlined]
  [4] eachcolumns(::typeof(Tables.add_or_widen!), ::Tables.Schema{(:a,), nothing}, ::Tables.IteratorRow{Dict{Any, Any}}, ::Tuple{Vector{Int64}}, ::Int64, ::Vararg{Any})
    @ Tables ~\.julia\packages\Tables\NSGZI\src\utils.jl:127
  [5] __buildcolumns(rowitr::Tables.IteratorWrapper{Vector{Dict}}, st::Int64, sch::Tables.Schema{(:a,), nothing}, columns::Tuple{Vector{Int64}}, rownbr::Int64, updated::Base.RefValue{Any})
    @ Tables ~\.julia\packages\Tables\NSGZI\src\fallbacks.jl:174
  [6] _buildcolumns(rowitr::Tables.IteratorWrapper{Vector{…}}, row::Tables.IteratorRow{Dict{…}}, st::Int64, sch::Tables.Schema{(:a,), nothing}, columns::Tuple{Tables.EmptyVector}, updated::Base.RefValue{Any})
    @ Tables ~\.julia\packages\Tables\NSGZI\src\fallbacks.jl:198
  [7] buildcolumns
    @ ~\.julia\packages\Tables\NSGZI\src\fallbacks.jl:227 [inlined]
  [8] _columns
    @ ~\.julia\packages\Tables\NSGZI\src\fallbacks.jl:274 [inlined]
  [9] columns
    @ ~\.julia\packages\Tables\NSGZI\src\fallbacks.jl:258 [inlined]
 [10] DataFrame(x::Vector{Dict}; copycols::Nothing)
    @ DataFrames ~\.julia\packages\DataFrames\58MUJ\src\other\tables.jl:57
 [11] DataFrame(x::Vector{Dict})
    @ DataFrames ~\.julia\packages\DataFrames\58MUJ\src\other\tables.jl:48 

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