Skip to content

Commit

Permalink
Backport PR #60318 on branch 2.3.x (TST (string dtype): resolve all x…
Browse files Browse the repository at this point in the history
…fails in JSON IO tests) (#60327)

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

(cherry picked from commit 9bc88c7)
  • Loading branch information
WillAyd authored Nov 15, 2024
1 parent aa8adfa commit fe1f4f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
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 @@ -6,8 +6,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

from pandas.core.dtypes.dtypes import (
CategoricalDtype,
DatetimeTZDtype,
Expand All @@ -26,10 +24,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 @@ -126,7 +120,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 @@ -118,7 +118,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 @@ -203,7 +203,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 @@ -281,7 +280,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 @@ -709,7 +707,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 @@ -721,6 +718,9 @@ def test_series_roundtrip_object(self, orient, dtype, object_series):
if orient != "split":
expected.name = None

if using_string_dtype():
expected = expected.astype("str")

tm.assert_series_equal(result, expected)

def test_series_roundtrip_empty(self, orient):
Expand Down Expand Up @@ -814,7 +814,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 @@ -827,7 +826,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 @@ -898,7 +896,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 @@ -959,7 +956,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)")
@pytest.mark.parametrize("unit", ["s", "ms", "us", "ns"])
def test_date_unit(self, unit, datetime_frame):
df = datetime_frame
Expand Down Expand Up @@ -1065,7 +1061,6 @@ def test_round_trip_exception(self, datapath):
res = res.fillna(np.nan, downcast=False)
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 @@ -1474,7 +1469,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

0 comments on commit fe1f4f9

Please sign in to comment.