Skip to content

to_json index with Null Value Broken in 1.0 #31801

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

Open
WillAyd opened this issue Feb 8, 2020 · 5 comments
Open

to_json index with Null Value Broken in 1.0 #31801

WillAyd opened this issue Feb 8, 2020 · 5 comments
Assignees
Labels
Bug IO JSON read_json, to_json, json_normalize Regression Functionality that used to work in a prior pandas version

Comments

@WillAyd
Copy link
Member

WillAyd commented Feb 8, 2020

Discovered by @ArtificialQualia in #31748

Previous behavior on 0.25.3:

>>> pd.Series([1], index=[np.nan]).to_json()
'{"null":1}'
>>> pd.Series([1], index=[pd.NaT]).to_json()
'{"null":1}'
>>> pd.Series([1], index=[None]).to_json()
'{"null":1}'

And now on master:

>>> pd.Series([1], index=[np.nan]).to_json()
'{"nan":1}'
>>> pd.Series([1], index=[pd.NaT]).to_json()
'{"null":1}'
>>> pd.Series([1], index=[None]).to_json()
'{"None":1}'

Note that pd.NA also just has its str representation written out:

>>> pd.Series([1], index=[pd.NA]).to_json()
'{"<NA>":1}'

pd.NaT still works because of this logic:

if (nanosecVal == get_nat()) {

So probably need to generalize for other "null" values

@WillAyd WillAyd added IO JSON read_json, to_json, json_normalize Regression Functionality that used to work in a prior pandas version labels Feb 8, 2020
@jbrockmendel
Copy link
Member

on master the pd.NA case is now giving '{"null":1}'

@WillAyd what is the desired behavior here? do you have a gameplan for this?

@WillAyd
Copy link
Member Author

WillAyd commented Mar 2, 2020

I'm not actively working on this but if someone wanted to I think the best solution is to take the NA check while encoding object keys:

if (nanosecVal == get_nat()) {

And move it up in the function so it gets hit generally. The get_nat function should probably be a generic null check, importable from the missing cython file

@simonjayhawkins
Copy link
Member

Previous behavior on 0.25.3:

>>> pd.Series([1], index=[np.nan]).to_json()
'{"null":1}'
>>> pd.Series([1], index=[pd.NaT]).to_json()
'{"null":1}'
>>> pd.Series([1], index=[None]).to_json()
'{"null":1}'

d75ee70 is the first bad commit
commit d75ee70
Author: William Ayd [email protected]
Date: Sat Aug 24 00:38:17 2019 +0200

Remove Encoding of values in char** For Labels (#27618)

@simonjayhawkins
Copy link
Member

on master the pd.NA case is now giving '{"null":1}'

this was fixed by #32214

35537dd is the first new commit
commit 35537dd
Author: Daniel Saxton [email protected]
Date: Wed Feb 26 06:39:55 2020 -0600

BUG: Cast pd.NA to pd.NaT in to_datetime (#32214)

@simonjayhawkins
Copy link
Member

pd.NaT still works because of this logic:

if (nanosecVal == get_nat()) {

this was also initially broken by #27618

>>> import pandas as pd
>>>
>>> pd.__version__
'0.26.0.dev0+228.gd75ee703e'
>>>
>>> pd.Series([1], index=[pd.NaT]).to_json()
'{"-9223372036854":1}'
>>>

however, this was fixed in #30977

9c33464 is the first new commit
commit 9c33464
Author: William Ayd [email protected]
Date: Sat Jan 18 07:34:12 2020 -0800

JSON Date Handling 1.0 Regressions (#30977)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO JSON read_json, to_json, json_normalize Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants