|
8 | 8 |
|
9 | 9 | from pandas.tests.extension import base
|
10 | 10 |
|
11 |
| -from .array import DecimalDtype, DecimalArray, make_data |
| 11 | +from .array import DecimalDtype, DecimalArray, make_data, to_decimal |
12 | 12 |
|
13 | 13 |
|
14 | 14 | @pytest.fixture
|
@@ -102,7 +102,7 @@ class TestInterface(BaseDecimal, base.BaseInterfaceTests):
|
102 | 102 |
|
103 | 103 | class TestConstructors(BaseDecimal, base.BaseConstructorsTests):
|
104 | 104 |
|
105 |
| - @pytest.mark.xfail(reason="not implemented constructor from dtype") |
| 105 | + @pytest.mark.skip(reason="not implemented constructor from dtype") |
106 | 106 | def test_from_dtype(self, data):
|
107 | 107 | # construct from our dtype & string dtype
|
108 | 108 | pass
|
@@ -240,9 +240,11 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators):
|
240 | 240 | context.traps[decimal.DivisionByZero] = divbyzerotrap
|
241 | 241 | context.traps[decimal.InvalidOperation] = invalidoptrap
|
242 | 242 |
|
243 |
| - @pytest.mark.skip(reason="divmod not appropriate for decimal") |
244 |
| - def test_divmod(self, data): |
245 |
| - pass |
| 243 | + def _check_divmod_op(self, s, op, other, exc=NotImplementedError): |
| 244 | + # We implement divmod |
| 245 | + super(TestArithmeticOps, self)._check_divmod_op( |
| 246 | + s, op, other, exc=None |
| 247 | + ) |
246 | 248 |
|
247 | 249 | def test_error(self):
|
248 | 250 | pass
|
@@ -315,3 +317,21 @@ def test_scalar_ops_from_sequence_raises(class_):
|
315 | 317 | expected = np.array([decimal.Decimal("2.0"), decimal.Decimal("4.0")],
|
316 | 318 | dtype="object")
|
317 | 319 | tm.assert_numpy_array_equal(result, expected)
|
| 320 | + |
| 321 | + |
| 322 | +@pytest.mark.parametrize("reverse, expected_div, expected_mod", [ |
| 323 | + (False, [0, 1, 1, 2], [1, 0, 1, 0]), |
| 324 | + (True, [2, 1, 0, 0], [0, 0, 2, 2]), |
| 325 | +]) |
| 326 | +def test_divmod_array(reverse, expected_div, expected_mod): |
| 327 | + # https://github.com/pandas-dev/pandas/issues/22930 |
| 328 | + arr = to_decimal([1, 2, 3, 4]) |
| 329 | + if reverse: |
| 330 | + div, mod = divmod(2, arr) |
| 331 | + else: |
| 332 | + div, mod = divmod(arr, 2) |
| 333 | + expected_div = to_decimal(expected_div) |
| 334 | + expected_mod = to_decimal(expected_mod) |
| 335 | + |
| 336 | + tm.assert_extension_array_equal(div, expected_div) |
| 337 | + tm.assert_extension_array_equal(mod, expected_mod) |
0 commit comments