Skip to content

Error when read_json created by to_json with orient='table and index=False #25170

Closed
@albertvillanova

Description

@albertvillanova

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
dfjson = df.to_json(orient='table', index=False)
result = pd.read_json(dfjson, orient='table')

Problem description

An error is raised while the original DataFrame should be recovered:

pandas/io/json/table_schema.py in parse_table_schema(json, precise_float)
    315     df = df.astype(dtypes)
    316 
--> 317     df = df.set_index(table['schema']['primaryKey'])
    318     if len(df.index.names) == 1:
    319         if df.index.name == 'index':

KeyError: 'primaryKey'

My pandas version is 0.24.0.

Expected Output

The expected output result should be the original DataFrame df.

Output of pd.show_versions()

pandas/util/_print_versions.py in (mod) 78 ("blosc", lambda mod: mod.__version__), 79 ("bottleneck", lambda mod: mod.__version__), ---> 80 ("tables", lambda mod: mod.__version__), 81 ("numexpr", lambda mod: mod.__version__), 82 ("feather", lambda mod: mod.__version__),

AttributeError: module 'tables' has no attribute 'version'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions