-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix pd.json_normalize to not skip the first element of a generator input #38698
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
898ccdf
BUG: Fix pd.json_normalize to not skip the first element of a generat…
avinashpancham 66f5ba6
Merge remote-tracking branch 'upstream/master' into GH35923
avinashpancham 8537705
Address comments
avinashpancham e885c86
Merge remote-tracking branch 'upstream/master' into GH35923
avinashpancham 89546ab
Address comments
avinashpancham bf25860
Remove whitespace
avinashpancham 9f1f2f9
Raise NotImplementedError for an input that is not an Iterable
avinashpancham 775f80e
Rename test name
avinashpancham f9e5332
Merge remote-tracking branch 'upstream/master' into GH35923
avinashpancham cc9cfae
Merge remote-tracking branch 'upstream/master' into GH35923
avinashpancham 2ca6be7
Merge remote-tracking branch 'upstream/master' into GH35923
avinashpancham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about inserting a call to next(data) to skip past the first element?
It's always good to be as lazy as possible but tbf I don't know how much that matters here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arw2019 wdym with skipping past the first line with "next(data)"? Cause we do not want to skip the first element.
Below I've written down my understanding and solution to the problem. But lmk if you see this differently!
The problem here is that in the old situation the first line of an input generator was consumed and not part of the output dataframe. This was caused by this line: https://github.com/pandas-dev/pandas/blob/master/pandas/io/json/_normalize.py#L270.
By consuming the whole generator and putting it in a list we don't have that issue anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay right your solution looks good
(There's actually already a TODO there about expanding the generator with nested records, as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah great. Wrt to the TODO, which one do you mean? I see this one:
TODO: handle record value which are lists, at least error reasonably
, but IMO that would justify its own PR since it is related to a different issueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, that TODO is beyond the scope of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just put a list(data) on L264 (you could even limit this to a Iterable type if you want)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this entire function needs to be split up into module level functions and cleaned up. I believe we have several open issues about this (but orthogonal to this PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put
list(data)
on L264, but limited it to typeIterator
and notIterable
since we use different conversion logic for dictsWrt to the splitting of the modules. I will add it to my list, but first I want to address some other PRs for dtypes.