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

ENH: automatically detect orient= for read_json if not supplied #52713

Open
1 of 3 tasks
chrisjdixon opened this issue Apr 18, 2023 · 3 comments · May be fixed by #60969
Open
1 of 3 tasks

ENH: automatically detect orient= for read_json if not supplied #52713

chrisjdixon opened this issue Apr 18, 2023 · 3 comments · May be fixed by #60969
Labels
Enhancement IO JSON read_json, to_json, json_normalize Needs Discussion Requires discussion from core team before further action

Comments

@chrisjdixon
Copy link

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

We'd love for Pandas to automatically detect what orient= should be for read_json if the orient was 'table' or 'split' and the argument wasn't supplied (seems unsupported as of 2.0.0).

Feature Description

For example, this would ideally not throw "ValueError: Mixing dicts with non-Series may lead to ambiguous ordering.", and instead work as if orient='table' was supplied to read_json:

import pandas as pd

df = pd.DataFrame({"A": [1, 2, 3],})
df.to_json('test.json', indent=1, orient= 'table')
read = pd.read_json('test.json')
print(read)

Alternative Solutions

I'm sorry but I'm not much of a programmer and wouldn't know where to begin designing a solution. Some except block that trys on the ValueError?

Additional Context

This isn't a huge problem but it recently caused several beginners many headaches and would be a subtle improvement to Pandas overall. If this is an easy fix then great, otherwise sorry for the dumb suggestion!

@chrisjdixon chrisjdixon added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 18, 2023
@csreddy98
Copy link

Are you suggesting that pandas should allow something like pd.read_json('test.json', orient='auto_detect') and parse the json file automatically?

Yes, that would be a cool new add-on.

@jesse-sealand
Copy link

I work with a lot of json and this would be a great enhancement.

@jbrockmendel jbrockmendel added the IO JSON read_json, to_json, json_normalize label Nov 1, 2023
@mroeschke mroeschke added Needs Discussion Requires discussion from core team before further action and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 17, 2024
@chandra-teajunkie
Copy link

Hi,
I would like to try working on this, if its still considered a valuable feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO JSON read_json, to_json, json_normalize Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants