Skip to content

TST: de-special-case test_EA_types #56494

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 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 21 additions & 1 deletion pandas/tests/extension/base/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,31 @@

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import ExtensionArray


class BaseParsingTests:
@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data):
def test_EA_types(self, engine, data, request):
if isinstance(data.dtype, pd.CategoricalDtype):
# in parsers.pyx _convert_with_dtype there is special-casing for
# Categorical that pre-empts _from_sequence_of_strings
pass
elif isinstance(data.dtype, pd.core.dtypes.dtypes.NumpyEADtype):
# These get unwrapped internally so are treated as numpy dtypes
# in the parsers.pyx code
pass
elif (
type(data)._from_sequence_of_strings.__func__
is ExtensionArray._from_sequence_of_strings.__func__
):
# i.e. the EA hasn't overridden _from_sequence_of_strings
mark = pytest.mark.xfail(
reason="_from_sequence_of_strings not implemented",
raises=NotImplementedError,
)
request.node.add_marker(mark)

df = pd.DataFrame({"with_dtype": pd.Series(data, dtype=str(data.dtype))})
csv_output = df.to_csv(index=False, na_rep=np.nan)
result = pd.read_csv(
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ def test_map(self, data, na_action):
result = data.map(lambda x: x, na_action=na_action)
tm.assert_extension_array_equal(result, data)

@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data):
expected_msg = r".*must implement _from_sequence_of_strings.*"
with pytest.raises(NotImplementedError, match=expected_msg):
super().test_EA_types(engine, data)

def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool):
if op_name in ["median", "mean", "std"]:
alt = ser.astype("int64")
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/extension/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
def test_fillna_length_mismatch(self, data_missing):
super().test_fillna_length_mismatch(data_missing)

@pytest.mark.parametrize("engine", ["c", "python"])
def test_EA_types(self, engine, data):
expected_msg = r".*must implement _from_sequence_of_strings.*"
with pytest.raises(NotImplementedError, match=expected_msg):
super().test_EA_types(engine, data)


# TODO: either belongs in tests.arrays.interval or move into base tests.
def test_fillna_non_scalar_raises(data_missing):
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,7 @@ def test_array_repr(self, data, size):


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


class TestNoNumericAccumulations(base.BaseAccumulateTests):
Expand Down