Skip to content

BUG: handle none values in json.normalize() #53773

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

Closed

Conversation

punndcoder28
Copy link
Contributor

@punndcoder28 punndcoder28 commented Jun 21, 2023

This PR fixes the error which is thrown when a field value in json is null while json_normalize it to a DataFrame. Implemented tests to validate the change

@punndcoder28 punndcoder28 force-pushed the fix-json-recursive-extract branch from 72c9816 to b4cab55 Compare June 21, 2023 17:59
@punndcoder28 punndcoder28 marked this pull request as ready for review June 21, 2023 18:04
@punndcoder28 punndcoder28 changed the title fix: handle none data in _recursive_extract BUG: handle none field in json.normalize() Jun 22, 2023
@punndcoder28 punndcoder28 changed the title BUG: handle none field in json.normalize() BUG: handle none values in json.normalize() Jun 22, 2023
@@ -490,6 +490,8 @@ def _pull_records(js: dict[str, Any], spec: list | str) -> list:
meta_keys = [sep.join(val) for val in _meta]

def _recursive_extract(data, path, seen_meta, level: int = 0) -> None:
if data is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this generally an issue if data is not list like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While running the tests I noticed while passing scalar values must be done in a list as is the expected behavior. But if I have a row of data in my json and one of the field values is null then the normalize() fails by throwing an exception when I instead expect it to ignore the entire row, which this change should do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test where a nested json value is a scalar like 2 as assert the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like this as my expected value?

expected = DataFrame(
            {
                "nested_field_id": 1,
            }
        )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi all, what is the status on this one? Any idea when it could be merged? (original request: #53719)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mroeschke Hi. In regard to the previous comment by me, is that what is required in the tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test where the input has something like "nested_field": [{"nested_field_id": [1]}],

@mroeschke mroeschke added the IO JSON read_json, to_json, json_normalize label Jun 22, 2023
@punndcoder28 punndcoder28 requested a review from mroeschke July 1, 2023 07:24
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Aug 1, 2023
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: is a child element contains NULL this results in a TypeError: 'NoneType' object is not iterable
3 participants