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

Support Vector{Dict{String,Any}} as a Table format #295

Closed
robsmith11 opened this issue Sep 14, 2022 · 4 comments
Closed

Support Vector{Dict{String,Any}} as a Table format #295

robsmith11 opened this issue Sep 14, 2022 · 4 comments

Comments

@robsmith11
Copy link

I see that support was added from #132 but it looks like it's only working for the case where keys are Symbols, not Strings, which for example is what JSON.Parse.parse() outputs.

Is there any reason to not support both cases?

julia> DataFrame([Dict(:x => rand(), :y => rand(Int)) for _ in 1:5])
5×2 DataFrame
 Row │ y                     x
     │ Int64                 Float64
─────┼─────────────────────────────────
   1 │ -6168923119116954553  0.733732
   2 │ -5238086163398295723  0.684467
   3 │  7996475788962267833  0.88606
   4 │ -1641761153302011089  0.0740284
   5 │  8099478073091371152  0.980377

julia> DataFrame([Dict("x" => rand(), "y" => rand(Int)) for _ in 1:5])
5×8 DataFrame
 Row │ slots                              keys                               vals                               ndel   count  age     idxfloor  maxprobe
     │ Array…                             Array…                             Array…                             Int64  Int64  UInt64  Int64     Int64
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ UInt8[0x00, 0x00, 0x00, 0x00, 0x…  [#undef, #undef, #undef, #undef,…  Real[#undef, #undef, #undef, #un…      0      2       2         9         0
   2 │ UInt8[0x00, 0x00, 0x00, 0x00, 0x…  [#undef, #undef, #undef, #undef,…  Real[#undef, #undef, #undef, #un…      0      2       2         9         0
   3 │ UInt8[0x00, 0x00, 0x00, 0x00, 0x…  [#undef, #undef, #undef, #undef,…  Real[#undef, #undef, #undef, #un…      0      2       2         9         0
   4 │ UInt8[0x00, 0x00, 0x00, 0x00, 0x…  [#undef, #undef, #undef, #undef,…  Real[#undef, #undef, #undef, #un…      0      2       2         9         0
   5 │ UInt8[0x00, 0x00, 0x00, 0x00, 0x…  [#undef, #undef, #undef, #undef,…  Real[#undef, #undef, #undef, #un…      0      2       2         9         0
@bkamins
Copy link
Member

bkamins commented Sep 14, 2022

AFAICT the thing is that normally assumes that column names are Symbol, but my opinion is that this case is so common that it could get a special handling. If @quinnj rejects this in Tables.jl we can discuss of adding a special constructor for this case in DataFrames.jl like now we have for AbstractDict{String} as this is the same case:

julia> DataFrame(Dict("A" => 1:2, "B" => 2:3))
2×2 DataFrame
 Row │ A      B
     │ Int64  Int64
─────┼──────────────
   1 │     1      2
   2 │     2      3

julia> Tables.columntable(Dict("A" => 1, "B" => 2:3))
ERROR: to treat Dict{String, Any} as a table, it must have a key type of `Symbol`, and a value type `<: AbstractVector`

quinnj added a commit that referenced this issue Sep 15, 2022
Implements #295. This is fairly simple. I think we didn't do this
before because it's a bit weird using plain Dicts because of the
lack of schema/column order. But using OrderedDicts makes this a natural
use.
@quinnj
Copy link
Member

quinnj commented Sep 15, 2022

Implemented in #296

quinnj added a commit that referenced this issue Sep 15, 2022
Implements #295. This is fairly simple. I think we didn't do this
before because it's a bit weird using plain Dicts because of the
lack of schema/column order. But using OrderedDicts makes this a natural
use.
@bkamins
Copy link
Member

bkamins commented Sep 16, 2022

@robsmith11 - OK to close it?

@robsmith11
Copy link
Author

Yep, just tested master branch and works great now. Thanks!

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