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 converting from JSONTables to DataFrame #7

Closed
vkc102 opened this issue Aug 30, 2019 · 3 comments
Closed

Error converting from JSONTables to DataFrame #7

vkc102 opened this issue Aug 30, 2019 · 3 comments

Comments

@vkc102
Copy link

vkc102 commented Aug 30, 2019

Hi,

Thanks for writing this package. Right now I am an encountering this error while trying the example in README.md

julia> jtable=jsontable(text);                                                                       
julia> df=DataFrame(jtable)                                                                          
ERROR: MethodError: no method matching size(::String)
Closest candidates are:
  size(::BitArray{1}) at bitarray.jl:77
  size(::BitArray{1}, ::Any) at bitarray.jl:81
  size(::Core.Compiler.StmtRange) at show.jl:1561
  ...

text here is a String of the json source. Not sure if it has something to do with DataFrames. Also my package versions are

(v1.1) pkg> status JSONTables                                                                        
    Status `~/.julia/environments/v1.1/Project.toml`
  [0f8b85d8] JSON3 v0.1.8
  [b9914132] JSONTables v0.1.2
  [bd369af6] Tables v0.2.11

(v1.1) pkg> status DataFrames                                                                        
    Status `~/.julia/environments/v1.1/Project.toml`
  [34da2185] Compat v2.1.0
  [a93c6f00] DataFrames v0.19.3
  [bd369af6] Tables v0.2.11

Thanks.

@quinnj
Copy link
Member

quinnj commented Aug 30, 2019

You'll have to provide more details; both these examples work for me:

julia> DataFrame(jsontable("""{
       "a": [1,2,3],
       "b": [4.1, null, 6.3],
       "c": ["7", "8", null]
       }"""))
3×3 DataFrame
│ Row │ a     │ b        │ c       │
│     │ Int64 │ Float64⍰ │ String⍰ │
├─────┼───────┼──────────┼─────────┤
│ 114.17       │
│ 22missing8       │
│ 336.3missing │

julia> DataFrame(jsontable("""[
       {"a": 1, "b": 4.1, "c": "7"},
       {"a": 2, "b": null, "c": "8"},
       {"a": 3, "b": 6.3, "c": null}
       ]"""))
3×3 DataFrame
│ Row │ a     │ b        │ c       │
│     │ Int64 │ Float64⍰ │ String⍰ │
├─────┼───────┼──────────┼─────────┤
│ 114.17       │
│ 22missing8       │
│ 336.3missing

@vkc102
Copy link
Author

vkc102 commented Sep 1, 2019

Oh yes, this example works for me as well. Where it was tripping me up before was

julia> text |> println                                                                                            
{
        "color_scheme": "Packages/Color Scheme - Default/Mariana.sublime-color-scheme",
        "dictionary": "Packages/Language - English/en_US.dic",
        "draw_white_space": "all",
        "font_face": "monospace 821",
        "font_size": "10",
        "theme": "Adaptive.sublime-theme"
}

julia> DataFrame(jsontable(text))                                                                                 
ERROR: MethodError: no method matching size(::String)
Closest candidates are:
  size(::BitArray{1}) at bitarray.jl:77
  size(::BitArray{1}, ::Any) at bitarray.jl:81
  size(::Core.Compiler.StmtRange) at show.jl:1561
  ...

Do the angle braces [ ] somehow matter for tables? I figured that the .json source would just appear as a 6X1 table.

Thanks again.

@quinnj
Copy link
Member

quinnj commented Sep 3, 2019

Ah, so in this case, your json input isn't a table; currently for JSONTables.jl, your json input needs to be an "object of arrays" or an "array of objects". I've put up a PR to better validate the input json, so you don't get the weird size(::String) error.

@quinnj quinnj closed this as completed in bb63b8f Sep 3, 2019
quinnj added a commit that referenced this issue Sep 3, 2019
Fix #7 by adding an additional validation check on columnar json sources
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