Skip to content

Commit fe1f4f9

Browse files
authored
Backport PR #60318 on branch 2.3.x (TST (string dtype): resolve all xfails in JSON IO tests) (#60327)
Backport PR #60318: TST (string dtype): resolve all xfails in JSON IO tests (cherry picked from commit 9bc88c7)
1 parent aa8adfa commit fe1f4f9

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

pandas/tests/io/json/test_json_table_schema.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import numpy as np
77
import pytest
88

9-
from pandas._config import using_string_dtype
10-
119
from pandas.core.dtypes.dtypes import (
1210
CategoricalDtype,
1311
DatetimeTZDtype,
@@ -26,10 +24,6 @@
2624
set_default_names,
2725
)
2826

29-
pytestmark = pytest.mark.xfail(
30-
using_string_dtype(), reason="TODO(infer_string)", strict=False
31-
)
32-
3327

3428
@pytest.fixture
3529
def df_schema():
@@ -126,7 +120,7 @@ def test_multiindex(self, df_schema, using_infer_string):
126120
expected["fields"][0] = {
127121
"name": "level_0",
128122
"type": "any",
129-
"extDtype": "string",
123+
"extDtype": "str",
130124
}
131125
expected["fields"][3] = {"name": "B", "type": "any", "extDtype": "str"}
132126
assert result == expected

pandas/tests/io/json/test_pandas.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def datetime_frame(self):
118118
# since that doesn't round-trip, see GH#33711
119119
df = DataFrame(
120120
np.random.default_rng(2).standard_normal((30, 4)),
121-
columns=Index(list("ABCD"), dtype=object),
121+
columns=Index(list("ABCD")),
122122
index=date_range("2000-01-01", periods=30, freq="B"),
123123
)
124124
df.index = df.index._with_freq(None)
@@ -203,7 +203,6 @@ def test_roundtrip_simple(self, orient, convert_axes, dtype, float_frame):
203203

204204
assert_json_roundtrip_equal(result, expected, orient)
205205

206-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
207206
@pytest.mark.parametrize("dtype", [False, np.int64])
208207
@pytest.mark.parametrize("convert_axes", [True, False])
209208
def test_roundtrip_intframe(self, orient, convert_axes, dtype, int_frame):
@@ -281,7 +280,6 @@ def test_roundtrip_empty(self, orient, convert_axes):
281280

282281
tm.assert_frame_equal(result, expected)
283282

284-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
285283
@pytest.mark.parametrize("convert_axes", [True, False])
286284
def test_roundtrip_timestamp(self, orient, convert_axes, datetime_frame):
287285
# TODO: improve coverage with date_format parameter
@@ -709,7 +707,6 @@ def test_series_roundtrip_simple(self, orient, string_series, using_infer_string
709707

710708
tm.assert_series_equal(result, expected)
711709

712-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
713710
@pytest.mark.parametrize("dtype", [False, None])
714711
def test_series_roundtrip_object(self, orient, dtype, object_series):
715712
data = StringIO(object_series.to_json(orient=orient))
@@ -721,6 +718,9 @@ def test_series_roundtrip_object(self, orient, dtype, object_series):
721718
if orient != "split":
722719
expected.name = None
723720

721+
if using_string_dtype():
722+
expected = expected.astype("str")
723+
724724
tm.assert_series_equal(result, expected)
725725

726726
def test_series_roundtrip_empty(self, orient):
@@ -814,7 +814,6 @@ def test_path(self, float_frame, int_frame, datetime_frame):
814814
df.to_json(path)
815815
read_json(path)
816816

817-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
818817
def test_axis_dates(self, datetime_series, datetime_frame):
819818
# frame
820819
json = StringIO(datetime_frame.to_json())
@@ -827,7 +826,6 @@ def test_axis_dates(self, datetime_series, datetime_frame):
827826
tm.assert_series_equal(result, datetime_series, check_names=False)
828827
assert result.name is None
829828

830-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
831829
def test_convert_dates(self, datetime_series, datetime_frame):
832830
# frame
833831
df = datetime_frame
@@ -898,7 +896,6 @@ def test_convert_dates_infer(self, infer_word):
898896
result = read_json(StringIO(ujson_dumps(data)))[["id", infer_word]]
899897
tm.assert_frame_equal(result, expected)
900898

901-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
902899
@pytest.mark.parametrize(
903900
"date,date_unit",
904901
[
@@ -959,7 +956,6 @@ def test_date_format_series_raises(self, datetime_series):
959956
with pytest.raises(ValueError, match=msg):
960957
ts.to_json(date_format="iso", date_unit="foo")
961958

962-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
963959
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
964960
def test_date_unit(self, unit, datetime_frame):
965961
df = datetime_frame
@@ -1065,7 +1061,6 @@ def test_round_trip_exception(self, datapath):
10651061
res = res.fillna(np.nan, downcast=False)
10661062
tm.assert_frame_equal(res, df)
10671063

1068-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
10691064
@pytest.mark.network
10701065
@pytest.mark.single_cpu
10711066
@pytest.mark.parametrize(
@@ -1474,7 +1469,6 @@ def test_data_frame_size_after_to_json(self):
14741469

14751470
assert size_before == size_after
14761471

1477-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
14781472
@pytest.mark.parametrize(
14791473
"index", [None, [1, 2], [1.0, 2.0], ["a", "b"], ["1", "2"], ["1.", "2."]]
14801474
)

0 commit comments

Comments
 (0)