Skip to content

Heterogeneous data sometimes detect wrong columns type  #20

Closed

Description

@attdona

There are combinations of heterogeneus data where the wrong column types are discovered.

For example:

using JSONTables
using Tables

nonhomogenous = """
[
    {"a": 1, "b": 2, "c": 3},
    {"b": 4, "c": 8, "d": 5}
]
"""

JSONTables.jsontable(nonhomogenous)

You got:

JSONTables.Table{false, JSON3.Array{JSON3.Object, Base.CodeUnits{UInt8, String}, Vector{UInt64}}}([:a, :b, :c, :d], Dict{Symbol, Type}(:a => Union{Missing, Int64}, :b => Int64, :d => Int64, :c => Int64), JSON3.Object[{
   "a": 1,
   "b": 2,
   "c": 3
}, {
   "b": 4,
   "c": 8,
   "d": 5
}])

d type is detected as Int64 and this throws an error when building a table:

ct = Tables.columntable(jt)
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type Int64

Activity

  1. attdona commented on Nov 29, 2021

    @attdona
    ContributorAuthor

    if I understand correctly the culprit is:

    types[k] = missT(typeof(v))

    This fix should works:

    types[k] = Union{Missing, missT(typeof(v))}
    
  2. quinnj commented on Nov 30, 2021

    @quinnj
    Member

    Yes, I think that's correct; mind making a PR @attdona ?

  3. quinnj commented on Oct 15, 2026

    @quinnj
    Member

    [comment generated via AI] Fixed by #21, released in 1.0.3. With JSONTables 1.1.0 the example gives d = Union{Missing, Int64}[missing, 5] for both string and JSON3 input (checked on Julia 1.12.6).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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