Skip to content

Commit 1387c4f

Browse files
authored
TST: de-special-case test_EA_types (#56494)
1 parent 9b2f8aa commit 1387c4f

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

pandas/tests/extension/base/io.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,31 @@
55

66
import pandas as pd
77
import pandas._testing as tm
8+
from pandas.core.arrays import ExtensionArray
89

910

1011
class BaseParsingTests:
1112
@pytest.mark.parametrize("engine", ["c", "python"])
12-
def test_EA_types(self, engine, data):
13+
def test_EA_types(self, engine, data, request):
14+
if isinstance(data.dtype, pd.CategoricalDtype):
15+
# in parsers.pyx _convert_with_dtype there is special-casing for
16+
# Categorical that pre-empts _from_sequence_of_strings
17+
pass
18+
elif isinstance(data.dtype, pd.core.dtypes.dtypes.NumpyEADtype):
19+
# These get unwrapped internally so are treated as numpy dtypes
20+
# in the parsers.pyx code
21+
pass
22+
elif (
23+
type(data)._from_sequence_of_strings.__func__
24+
is ExtensionArray._from_sequence_of_strings.__func__
25+
):
26+
# i.e. the EA hasn't overridden _from_sequence_of_strings
27+
mark = pytest.mark.xfail(
28+
reason="_from_sequence_of_strings not implemented",
29+
raises=NotImplementedError,
30+
)
31+
request.node.add_marker(mark)
32+
1333
df = pd.DataFrame({"with_dtype": pd.Series(data, dtype=str(data.dtype))})
1434
csv_output = df.to_csv(index=False, na_rep=np.nan)
1535
result = pd.read_csv(

pandas/tests/extension/test_datetime.py

-6
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ def test_map(self, data, na_action):
113113
result = data.map(lambda x: x, na_action=na_action)
114114
tm.assert_extension_array_equal(result, data)
115115

116-
@pytest.mark.parametrize("engine", ["c", "python"])
117-
def test_EA_types(self, engine, data):
118-
expected_msg = r".*must implement _from_sequence_of_strings.*"
119-
with pytest.raises(NotImplementedError, match=expected_msg):
120-
super().test_EA_types(engine, data)
121-
122116
def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool):
123117
if op_name in ["median", "mean", "std"]:
124118
alt = ser.astype("int64")

pandas/tests/extension/test_interval.py

-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
9090
def test_fillna_length_mismatch(self, data_missing):
9191
super().test_fillna_length_mismatch(data_missing)
9292

93-
@pytest.mark.parametrize("engine", ["c", "python"])
94-
def test_EA_types(self, engine, data):
95-
expected_msg = r".*must implement _from_sequence_of_strings.*"
96-
with pytest.raises(NotImplementedError, match=expected_msg):
97-
super().test_EA_types(engine, data)
98-
9993

10094
# TODO: either belongs in tests.arrays.interval or move into base tests.
10195
def test_fillna_non_scalar_raises(data_missing):

pandas/tests/extension/test_sparse.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,7 @@ def test_array_repr(self, data, size):
446446

447447

448448
class TestParsing(BaseSparseTests, base.BaseParsingTests):
449-
@pytest.mark.parametrize("engine", ["c", "python"])
450-
def test_EA_types(self, engine, data):
451-
expected_msg = r".*must implement _from_sequence_of_strings.*"
452-
with pytest.raises(NotImplementedError, match=expected_msg):
453-
super().test_EA_types(engine, data)
449+
pass
454450

455451

456452
class TestNoNumericAccumulations(base.BaseAccumulateTests):

0 commit comments

Comments
 (0)