Skip to content

TST (string dtype): resolve all xfails in JSON IO tests #60318

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
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 1 addition & 7 deletions pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

from pandas.core.dtypes.dtypes import (
CategoricalDtype,
DatetimeTZDtype,
Expand All @@ -27,10 +25,6 @@
set_default_names,
)

pytestmark = pytest.mark.xfail(
using_string_dtype(), reason="TODO(infer_string)", strict=False
)


@pytest.fixture
def df_schema():
Expand Down Expand Up @@ -127,7 +121,7 @@ def test_multiindex(self, df_schema, using_infer_string):
expected["fields"][0] = {
"name": "level_0",
"type": "any",
"extDtype": "string",
"extDtype": "str",
}
expected["fields"][3] = {"name": "B", "type": "any", "extDtype": "str"}
assert result == expected
Expand Down
14 changes: 4 additions & 10 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def datetime_frame(self):
# since that doesn't round-trip, see GH#33711
df = DataFrame(
np.random.default_rng(2).standard_normal((30, 4)),
columns=Index(list("ABCD"), dtype=object),
columns=Index(list("ABCD")),
index=date_range("2000-01-01", periods=30, freq="B"),
)
df.index = df.index._with_freq(None)
Expand Down Expand Up @@ -184,7 +184,6 @@ def test_roundtrip_simple(self, orient, convert_axes, dtype, float_frame):

assert_json_roundtrip_equal(result, expected, orient)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.parametrize("dtype", [False, np.int64])
@pytest.mark.parametrize("convert_axes", [True, False])
def test_roundtrip_intframe(self, orient, convert_axes, dtype, int_frame):
Expand Down Expand Up @@ -270,7 +269,6 @@ def test_roundtrip_empty(self, orient, convert_axes):

tm.assert_frame_equal(result, expected)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.parametrize("convert_axes", [True, False])
def test_roundtrip_timestamp(self, orient, convert_axes, datetime_frame):
# TODO: improve coverage with date_format parameter
Expand Down Expand Up @@ -698,7 +696,6 @@ def test_series_roundtrip_simple(self, orient, string_series, using_infer_string

tm.assert_series_equal(result, expected)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
@pytest.mark.parametrize("dtype", [False, None])
def test_series_roundtrip_object(self, orient, dtype, object_series):
data = StringIO(object_series.to_json(orient=orient))
Expand All @@ -710,6 +707,9 @@ def test_series_roundtrip_object(self, orient, dtype, object_series):
if orient != "split":
expected.name = None

if using_string_dtype():
expected = expected.astype(pd.StringDtype(na_value=np.nan))
Copy link
Member

Choose a reason for hiding this comment

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

BTW you can also use the shorter astype("str") for general cases where you want to ensure the default string dtype is used (and which might additionally also be more forward looking if at some point the default na_value changes, then we would have less work updating the tests)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good to know - I missed that on the prior SQL PR so will go back and do that too, so we have one consistent method internally

Copy link
Member

Choose a reason for hiding this comment

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

I think on the sql PR you wanted to construct the actual dtype instance? In that case the above is fine. I am mostly using "str" in the tests.


tm.assert_series_equal(result, expected)

def test_series_roundtrip_empty(self, orient):
Expand Down Expand Up @@ -808,7 +808,6 @@ def test_path(self, float_frame, int_frame, datetime_frame):
df.to_json(path)
read_json(path)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_axis_dates(self, datetime_series, datetime_frame):
# frame
json = StringIO(datetime_frame.to_json())
Expand All @@ -821,7 +820,6 @@ def test_axis_dates(self, datetime_series, datetime_frame):
tm.assert_series_equal(result, datetime_series, check_names=False)
assert result.name is None

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_convert_dates(self, datetime_series, datetime_frame):
# frame
df = datetime_frame
Expand Down Expand Up @@ -912,7 +910,6 @@ def test_convert_dates_infer(self, infer_word):
result = read_json(StringIO(ujson_dumps(data)))[["id", infer_word]]
tm.assert_frame_equal(result, expected)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
@pytest.mark.parametrize(
"date,date_unit",
[
Expand Down Expand Up @@ -973,7 +970,6 @@ def test_date_format_series_raises(self, datetime_series):
with pytest.raises(ValueError, match=msg):
ts.to_json(date_format="iso", date_unit="foo")

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_date_unit(self, unit, datetime_frame):
df = datetime_frame
df["date"] = Timestamp("20130101 20:43:42").as_unit("ns")
Expand Down Expand Up @@ -1114,7 +1110,6 @@ def test_round_trip_exception(self, datapath):
res = res.fillna(np.nan)
tm.assert_frame_equal(res, df)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.network
@pytest.mark.single_cpu
@pytest.mark.parametrize(
Expand Down Expand Up @@ -1555,7 +1550,6 @@ def test_data_frame_size_after_to_json(self):

assert size_before == size_after

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.parametrize(
"index", [None, [1, 2], [1.0, 2.0], ["a", "b"], ["1", "2"], ["1.", "2."]]
)
Expand Down