Skip to content

loaders_extra.py silently mis-parses index-oriented JSON (transposed, no error) #405

Description

@yakew7

Where: faircode/loaders_extra.py's JSON orientation handling (the {"columns", "data"} <= keys split-orient check).

The gap: the existing code correctly detects and handles split-orient JSON, with a comment explaining why (a records-shaped file with columns literally named "columns"/"data" would otherwise silently misparse). A 4th real pandas export orientation - orient="index" - hits the same silent-wrong-shape problem and isn't detected at all. Verified directly:

>>> df = pd.DataFrame({'sex': ['M','F'], 'age': [30, 40]}, index=['a','b'])
>>> df.to_json('idx.json', orient='index')
>>> from faircode.loaders_extra import read_table
>>> read_table('idx.json')
      a   b
sex   M   F
age  30  40

The result is transposed relative to the true data (sex/age end up as row labels, a/b as columns) - pd.read_json(path)'s default orientation guess ("columns") is structurally indistinguishable from a dict-of-dicts written with orient="index", so it silently produces the wrong shape instead of erroring.

Why it matters: unlike the already-handled split-orient ambiguity, this produces a plausible-looking but completely wrong DataFrame with no error anywhere - a user profiling this file gets confident-sounding, entirely incorrect results.

Suggested fix: detect the index-orient shape (a dict whose every top-level value is itself a dict, not matching the split-orient {"columns","data"} shape) and either parse it correctly via orient="index" or raise a clear "ambiguous JSON orientation" error rather than silently guessing wrong.

Activity

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

Metadata

Metadata

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions