Skip to content

pd.NA is converted to {} instead of null with pd.DataFrame.to_json #31615

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
pvieito opened this issue Feb 3, 2020 · 3 comments · Fixed by #31748
Closed

pd.NA is converted to {} instead of null with pd.DataFrame.to_json #31615

pvieito opened this issue Feb 3, 2020 · 3 comments · Fixed by #31748
Labels
IO JSON read_json, to_json, json_normalize NA - MaskedArrays Related to pd.NA and nullable extension arrays
Milestone

Comments

@pvieito
Copy link

pvieito commented Feb 3, 2020

Code Sample

import numpy as np
import pandas as pd

pd.DataFrame([[np.nan]], columns=["NA"]).to_json(orient="records")
# '[{"NA":null}]'
pd.DataFrame([[None]], columns=["NA"]).to_json(orient="records")
# '[{"NA":null}]'
pd.DataFrame([[pd.NA]], columns=["NA"]).to_json(orient="records")
# '[{"NA":{}}]'

Problem Description

pd.NA should behave as np.nan and None when converting a DataFrame to JSON.

Expected Output

In the resulting JSON the pd.NA instances should be converted to JSON's null.

@jorisvandenbossche jorisvandenbossche added IO JSON read_json, to_json, json_normalize NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Feb 3, 2020
@jorisvandenbossche
Copy link
Member

@pvieito Thanks for the report! That's indeed buggy

@itsshavar
Copy link

json writer is having some issue

@ArtificialQualia
Copy link
Contributor

I got this one, some changes are needed in ujson.

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 NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants