Skip to content

Commit

Permalink
TST (string dtype): resolve all xfails in JSON IO tests (#60318)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored Nov 15, 2024
1 parent 45aa7a5 commit 9bc88c7
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 @@ -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("str")

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

0 comments on commit 9bc88c7

Please sign in to comment.