Skip to content

Fix NoneType error when pulling non existent field #30145

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 2 commits into from
Jan 1, 2020

Conversation

bolkedebruin
Copy link
Contributor

@bolkedebruin bolkedebruin commented Dec 8, 2019

If normalizing a jsonstruct a field can be absent
due to a schema change.

@bolkedebruin bolkedebruin force-pushed the fix_schema_change branch 3 times, most recently from 37b4b33 to d202ead Compare December 8, 2019 22:12
@WillAyd
Copy link
Member

WillAyd commented Dec 9, 2019

Can you add test(s)? Typically the first thing we look for in a PR

@bolkedebruin
Copy link
Contributor Author

@WillAyd of course. Test has been added.

@WillAyd
Copy link
Member

WillAyd commented Dec 9, 2019

Thanks for the test. I don't really agree with the change though - why wouldn't you want this to raise a TypeError?

@bolkedebruin
Copy link
Contributor Author

bolkedebruin commented Dec 9, 2019

Imagine if I have 3 records:

[{'state': 'Florida', 'info': [1, 2,]}]
[{'state': 'Texas', 'info': None}]
[{'state': 'California', 'info': [2,3,]}]

I cannot use json_normalize now with record_path=['info'] as the field for the second record is None. That's perfectly valid for this field, but not acceptable to pandas. Its a real world case btw.

if the key is not there it should raise a KeyError not a TypeError I think (I can change the test to verify for that).

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

OK I think I see the point. Few things to improve this

@WillAyd WillAyd added the IO JSON read_json, to_json, json_normalize label Dec 9, 2019
@bolkedebruin bolkedebruin force-pushed the fix_schema_change branch 2 times, most recently from 9f134b0 to 1ece957 Compare December 10, 2019 09:40
@bolkedebruin
Copy link
Contributor Author

@WillAyd I have changed it to use the fixture, but I'm not entirely happy with it. The fixture sets it to float('NaN') which is different from 'None'. Now I am testing against an iterable and catching a TypeError which changes the gist of it.

What do you think?

@bolkedebruin bolkedebruin requested a review from WillAyd December 10, 2019 09:44
@bolkedebruin bolkedebruin force-pushed the fix_schema_change branch 3 times, most recently from b0cf30d to 8aef446 Compare December 10, 2019 20:18
@bolkedebruin bolkedebruin requested a review from jreback December 10, 2019 22:07
@bolkedebruin
Copy link
Contributor Author

@jreback @WillAyd ready for re-review

@bolkedebruin bolkedebruin force-pushed the fix_schema_change branch 2 times, most recently from c93e987 to a7fd904 Compare December 13, 2019 10:34
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

looks good. ping when green.

@bolkedebruin bolkedebruin force-pushed the fix_schema_change branch 5 times, most recently from f48eda9 to e17214d Compare December 15, 2019 20:50
@bolkedebruin
Copy link
Contributor Author

@jreback ping

@bolkedebruin bolkedebruin force-pushed the fix_schema_change branch 2 times, most recently from 1b489ef to 2f34c5a Compare December 16, 2019 21:04
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Glad the last thing worked; definitely makes things simpler. A few more details to hash out but going in the right direction

@bolkedebruin bolkedebruin force-pushed the fix_schema_change branch 3 times, most recently from 351017f to 623fe37 Compare December 18, 2019 12:47
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm. One comment that's not a blocker for me but others may disagree

Over to you @jreback

@WillAyd WillAyd added this to the 1.0 milestone Dec 18, 2019
@bolkedebruin
Copy link
Contributor Author

Ping @jreback

@bolkedebruin
Copy link
Contributor Author

Friendly reminder @jreback

@jreback
Copy link
Contributor

jreback commented Dec 27, 2019

can you merge master and will look again

If normalizing a jsonstruct a field can be set to None
due to a schema change.

Co-Authored-By: William Ayd <[email protected]>
@bolkedebruin
Copy link
Contributor Author

@jreback rebased. Or do you truly want me to merge master into my branch?

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Merge master. There are some CI failures that should be fixed by doing that.

@bolkedebruin
Copy link
Contributor Author

@jreback all green again.

@jreback jreback merged commit f9fb02e into pandas-dev:master Jan 1, 2020
@jreback
Copy link
Contributor

jreback commented Jan 1, 2020

thanks @bolkedebruin very nice

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NoneType error during json_normalize due to schema change
5 participants