Skip to content

REF: de-duplicate test_divmod_series_array #54413

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
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
6 changes: 5 additions & 1 deletion pandas/tests/extension/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def data():

@pytest.fixture
def data_for_twos():
"""Length-100 array in which all the elements are two."""
"""
Length-100 array in which all the elements are two.

Call pytest.skip in your fixture if the dtype does not support divmod.
"""
raise NotImplementedError


Expand Down
11 changes: 5 additions & 6 deletions pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def data_for_grouping():
)


@pytest.fixture
def data_for_twos(dtype):
pytest.skip("Not a numeric dtype")


class BaseJSON:
pass

Expand Down Expand Up @@ -317,12 +322,6 @@ def test_add_series_with_extension_array(self, data):
with pytest.raises(TypeError, match="unsupported"):
ser + data

@pytest.mark.xfail(reason="not implemented")
def test_divmod_series_array(self):
# GH 23287
# skipping because it is not implemented
super().test_divmod_series_array()


class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests):
pass
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,16 @@ def data_missing_for_sorting(data_for_grouping):
def data_for_twos(data):
"""Length-100 array in which all the elements are two."""
pa_dtype = data.dtype.pyarrow_dtype
if pa.types.is_integer(pa_dtype) or pa.types.is_floating(pa_dtype):
if (
pa.types.is_integer(pa_dtype)
or pa.types.is_floating(pa_dtype)
or pa.types.is_decimal(pa_dtype)
or pa.types.is_duration(pa_dtype)
):
return pd.array([2] * 100, dtype=data.dtype)
# tests will be xfailed where 2 is not a valid scalar for pa_dtype
return data
# TODO: skip otherwise?


@pytest.fixture
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def data_missing_for_sorting():
return Categorical(["A", None, "B"], categories=["B", "A"], ordered=True)


@pytest.fixture
def data_for_twos(dtype):
pytest.skip("Not a numeric dtype")


@pytest.fixture
def na_value():
return np.nan
Expand Down Expand Up @@ -263,11 +268,6 @@ def test_add_series_with_extension_array(self, data):
with pytest.raises(TypeError, match="cannot perform|unsupported operand"):
ser + data

def test_divmod_series_array(self):
# GH 23287
# skipping because it is not implemented
pass


class TestComparisonOps(base.BaseComparisonOpsTests):
def _compare_other(self, s, data, op, other):
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def data_for_grouping(dtype):
)


@pytest.fixture
def data_for_twos(dtype):
pytest.skip("Not a numeric dtype.")


@pytest.fixture
def na_cmp():
def cmp(a, b):
Expand Down Expand Up @@ -142,11 +147,6 @@ def test_add_series_with_extension_array(self, data):
with pytest.raises(TypeError, match=msg):
ser + data

def test_divmod_series_array(self):
# GH 23287
# skipping because it is not implemented
pass


class TestCasting(BaseDatetimeTests, base.BaseCastingTests):
pass
Expand Down
13 changes: 8 additions & 5 deletions pandas/tests/extension/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def data_for_grouping(allow_in_pandas, dtype):
)


@pytest.fixture
def data_for_twos(dtype):
if dtype.kind == "O":
pytest.skip("Not a numeric dtype")
arr = np.ones(100) * 2
return NumpyExtensionArray._from_sequence(arr, dtype=dtype)


@pytest.fixture
def skip_numpy_object(dtype, request):
"""
Expand Down Expand Up @@ -278,11 +286,6 @@ class TestArithmetics(BaseNumPyTests, base.BaseArithmeticOpsTests):
def test_divmod(self, data):
super().test_divmod(data)

@skip_nested
def test_divmod_series_array(self, data):
ser = pd.Series(data)
self._check_divmod_op(ser, divmod, data)

@skip_nested
def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
super().test_arith_series_with_scalar(data, all_arithmetic_operators)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def data(dtype):

@pytest.fixture
def data_for_twos(dtype):
return PeriodArray(np.ones(100) * 2, dtype=dtype)
pytest.skip("Not a numeric dtype")


@pytest.fixture
Expand Down