Skip to content

Commit a908700

Browse files
committed
move methods tests, elementwise rounding
1 parent e2a4168 commit a908700

File tree

8 files changed

+39
-16
lines changed

8 files changed

+39
-16
lines changed

pandas/tests/extension/base/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class TestMyDtype(BaseDtypeTests):
5353
BaseArithmeticOpsTests,
5454
BaseComparisonOpsTests,
5555
BaseOpsUtil,
56-
BaseRoundingTests,
5756
BaseUnaryOpsTests,
5857
)
5958
from pandas.tests.extension.base.printing import BasePrintingTests
@@ -87,7 +86,6 @@ class ExtensionTests(
8786
BaseArithmeticOpsTests,
8887
BaseComparisonOpsTests,
8988
BaseUnaryOpsTests,
90-
BaseRoundingTests,
9189
BasePrintingTests,
9290
BaseReduceTests,
9391
BaseReshapingTests,

pandas/tests/extension/base/methods.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,10 @@ def test_equals(self, data, na_value, as_series, box):
698698
def test_equals_same_data_different_object(self, data):
699699
# https://github.com/pandas-dev/pandas/issues/34660
700700
assert pd.Series(data).equals(pd.Series(data))
701+
702+
def test_round(self, data):
703+
if not data.dtype._is_numeric:
704+
pytest.skip("Round is only valid for numeric dtypes")
705+
result = pd.Series(data).round()
706+
expected = pd.Series([np.round(element) if pd.notna(element) else element for element in data], dtype=data.dtype)
707+
tm.assert_series_equal(result, expected)

pandas/tests/extension/base/ops.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,3 @@ def test_unary_ufunc_dunder_equivalence(self, data, ufunc):
263263
else:
264264
alt = ufunc(data)
265265
tm.assert_extension_array_equal(result, alt)
266-
267-
268-
class BaseRoundingTests:
269-
def test_round(self, data):
270-
result = pd.Series(data).round()
271-
expected = pd.Series(np.round(data), dtype=data.dtype)
272-
tm.assert_series_equal(result, expected)

pandas/tests/extension/test_arrow.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,19 @@ def _get_arith_xfail_marker(self, opname, pa_dtype):
10111011
)
10121012

10131013
return mark
1014+
1015+
def test_round(self, data, request):
1016+
mark = pytest.mark.xfail(
1017+
# raises=pa.ArrowInvalid,
1018+
reason="ArrowArray.round converts dtype to double",
1019+
)
1020+
if pa.types.is_float32(data.dtype.pyarrow_dtype) or pa.types.is_float64(
1021+
data.dtype.pyarrow_dtype
1022+
):
1023+
mark = None
1024+
if mark is not None:
1025+
request.node.add_marker(mark)
1026+
super().test_round(data)
10141027

10151028
def test_arith_series_with_scalar(self, data, all_arithmetic_operators, request):
10161029
pa_dtype = data.dtype.pyarrow_dtype

pandas/tests/extension/test_interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_invert(self, data):
9696
super().test_invert(data)
9797

9898
@pytest.mark.xfail(
99-
reason="IntervalArray.round is not implemented."
99+
reason="Round is not valid for IntervalArray."
100100
)
101101
def test_round(self, data):
102102
super().test_round(data)

pandas/tests/extension/test_masked.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,15 @@ def test_invert(self, data, request):
358358
)
359359
request.node.add_marker(mark)
360360
super().test_invert(data)
361+
362+
def test_round(self, data, request):
363+
if data.dtype == "boolean":
364+
mark = pytest.mark.xfail(reason="Cannot round boolean dtype")
365+
request.node.add_marker(mark)
366+
super().test_round(data)
361367

362368

363369
class Test2DCompat(base.Dim2CompatTests):
364370
pass
365371

366372

367-
class TestRounding(base.BaseRoundingTests):
368-
def test_round(self, data, request):
369-
if data.dtype == "boolean":
370-
mark = pytest.mark.xfail(reason="Cannot round boolean dtype")
371-
request.node.add_marker(mark)
372-
super().test_round(data)

pandas/tests/extension/test_numpy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ def test_insert_invalid(self, data, invalid_scalar):
270270
# NumpyExtensionArray[object] can hold anything, so skip
271271
super().test_insert_invalid(data, invalid_scalar)
272272

273+
@pytest.mark.xfail(
274+
reason="NumpyExtensionArray.round is not implemented."
275+
)
276+
def test_round(self, data):
277+
super().test_round(data)
278+
273279

274280
class TestArithmetics(BaseNumPyTests, base.BaseArithmeticOpsTests):
275281
divmod_exc = None

pandas/tests/extension/test_sparse.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ def test_map_raises(self, data, na_action):
346346
with pytest.raises(ValueError, match=msg):
347347
data.map(lambda x: np.nan, na_action=na_action)
348348

349+
@pytest.mark.xfail(
350+
reason="SpareArray.round not implemented."
351+
)
352+
def test_round(self, data):
353+
super().test_round(data)
354+
349355

350356
class TestCasting(BaseSparseTests, base.BaseCastingTests):
351357
@pytest.mark.xfail(raises=TypeError, reason="no sparse StringDtype")

0 commit comments

Comments
 (0)