Skip to content

BUG: Fixed encoding of pd.NA with to_json #31748

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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
TST: remove label tests
  • Loading branch information
ArtificialQualia committed Feb 7, 2020
commit 2f3853e621d2168423c616bd34ab67d9465ef21b
14 changes: 0 additions & 14 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1677,21 +1677,7 @@ def test_json_pandas_na(self):
result = pd.DataFrame([[pd.NA]]).to_json()
assert result == '{"0":{"0":null}}'

def test_json_pandas_na_label(self):
# GH 31615
result = pd.DataFrame({pd.NA: ["a"]}).to_json()
assert result == '{"<NA>":{"0":"a"}}'

def test_json_pandas_nulls(self, nulls_fixture):
Copy link
Member

Choose a reason for hiding this comment

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

@simonjayhawkins do you know of an easy way to add pd.NA to nulls_fixture inline during injection? Or would adding another fixture on top be the only way?

Copy link
Member

Choose a reason for hiding this comment

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

since we already have two nulls_fixtures (nulls_fixture and unique_nulls_fixture), I think adding another could be the simplest way for now.

I think, in general, simpler to skip than to add a extra parameter (although I've not kept up with the latest pytest releases).

There is not a huge number of tests using the nulls_fixture and maybe tests that do should also test for pandas.NA, either now of in the future. So an alternative could be to add pd.NA to the existing nulls fixture and either skip of xfail.

# GH 31615
result = pd.DataFrame([[nulls_fixture]]).to_json()
assert result == '{"0":{"0":null}}'

def test_json_pandas_nulls_labels(self, nulls_fixture):
# GH 31615
result = pd.DataFrame({nulls_fixture: ["a"]}).to_json()
if nulls_fixture is pd.NaT:
null_string = "null"
else:
null_string = str(nulls_fixture)
assert result == '{"' + null_string + '":{"0":"a"}}'