Skip to content

arraytable (objecttable) fails when the argument is a nested table #22

@sprmnt21

Description

@sprmnt21

I wanted to see the json file corresponding to a dataframe that has dataframes as elements in one of the columns.

3×3 DataFrame
 Row │ f       oc     sdf
     │ String  Int64  DataFrame
─────┼──────────────────────────────
   1 │ f1          1  3×2 DataFrame
   2 │ f2          2  2×2 DataFrame
   3 │ f3          3  3×2 DataFrame

I have previously verified that

julia> Tables.istable(dfn)
true

but I get this result

julia> objecttable(dfn)
ERROR: ArgumentError: DataFrame doesn't have a defined `StructTypes.StructType`
Stacktrace:
...

I wonder if it is possible to manage this type of structures

if i use jsontable on this string (http://bl.ocks.org/nautat/4085017)

jdata = "[
    {
        \"name\":\"bob\",
        \"salary\":13000,
        \"friends\":[
            {
                \"name\": \"sarah\",
                \"salary\":10000
            },
            {
                \"name\": \"bill\",
                \"salary\":5000
            }
        ]
    },
    {
        \"name\":\"marge\",
        \"salary\":10000,
        \"friends\":[
            {
                \"name\": \"rhonda\",
                \"salary\":10000
            },
            {
                \"name\": \"mike\",
                \"salary\":5000,
                \"hobbies\":[
                    {
                        \"name\":\"surfing\",
                        \"frequency\":10
                    },
                    {
                        \"name\":\"surfing\",
                        \"frequency\":15
                    }
                ]
            }
        ]
    },
    {
        \"name\":\"joe\",
        \"salary\":10000,
        \"friends\":[
            {
                \"name\": \"harry\",
                \"salary\":10000
            },
            {
                \"name\": \"sally\",
                \"salary\":5000
            }
        ]
    }
]"

and then i try to get the dataframe

julia> jsontable(jdata)
JSONTables.Table{false, JSON3.Array{JSON3.Object, Base.CodeUnits{UInt8, String}, Vector{UInt64}}}([:name, :salary, :friends], Dict{Symbol, Type}(:name => String, :salary => Int64, :friends => JSON3.Array{JSON3.Object, Base.CodeUnits{UInt8, String}, SubArray{UInt64, 1, Vector{UInt64}, Tuple{UnitRange{Int64}}, true}}), JSON3.Object[{
...



julia> DataFrame(jsontable(jdata))
3×3 DataFrame
 Row │ name    salary  friends
     │ String  Int64   Array…
─────┼───────────────────────────────────────────────────
   1 │ bob      13000  JSON3.Object[{\n     "name": "sa…
   2 │ marge    10000  JSON3.Object[{\n     "name": "rh…
   3 │ joe      10000  JSON3.Object[{\n     "name": "ha…

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions