diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index cd5e55d9871b2f..fd8053841d78e1 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -119,6 +119,12 @@ def test_direct_arith_with_series_returns_not_implemented(self, data): "{} does not implement add".format(data.__class__.__name__) ) + def test_arith_diff_lengths(self, data, all_arithmetic_operators): + op = self.get_op_from_name(all_arithmetic_operators) + other = data[:3] + with pytest.raises(ValueError): + op(data, other) + class BaseComparisonOpsTests(BaseOpsUtil): """Various Series and DataFrame comparison ops methods.""" @@ -164,3 +170,9 @@ def test_direct_arith_with_series_returns_not_implemented(self, data): raise pytest.skip( "{} does not implement __eq__".format(data.__class__.__name__) ) + + def test_compare_diff_lengths(self, data, all_compare_operators): + op = self.get_op_from_name(all_compare_operators) + other = data[:3] + with pytest.raises(ValueError): + op(data, other) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 6281c5360cd031..5090ff6b3a4702 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -299,6 +299,12 @@ def _check_divmod_op(self, s, op, other, exc=NotImplementedError): def test_error(self): pass + def test_arith_diff_lengths(self): + # TODO + # Raise ValueError when carrying out arithmetic operation + # on two decimal arrays of different lengths + pass + class TestComparisonOps(BaseDecimal, base.BaseComparisonOpsTests): @@ -324,6 +330,11 @@ def test_compare_array(self, data, all_compare_operators): for i in alter] self._compare_other(s, data, op_name, other) + def test_compare_diff_lengths(self): + # TODO: + # Raise ValueError when comparing decimal arrays of different lenghts + pass + class DecimalArrayWithoutFromSequence(DecimalArray): """Helper class for testing error handling in _from_sequence.""" diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index a35997b07fd83d..209a85e300b549 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -291,9 +291,13 @@ def _check_divmod_op(self, s, op, other, exc=NotImplementedError): s, op, other, exc=TypeError ) + def test_arith_diff_lengths(self): + pass + class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests): - pass + def test_compare_diff_lengths(self): + pass class TestPrinting(BaseJSON, base.BasePrintingTests): diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index 6106bc3d586205..c8079babc9e91e 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -215,6 +215,9 @@ def _check_divmod_op(self, s, op, other, exc=NotImplementedError): s, op, other, exc=TypeError ) + def test_arith_diff_lengths(self): + pass + class TestComparisonOps(base.BaseComparisonOpsTests): @@ -233,3 +236,11 @@ def _compare_other(self, s, data, op_name, other): else: with pytest.raises(TypeError): op(data, other) + + @pytest.mark.parametrize('op_name', + ['__eq__', '__ne__']) + def test_compare_diff_lengths(self, data, op_name): + op = self.get_op_from_name(op_name) + other = data[:3] + with pytest.raises(ValueError): + op(data, other) diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 08e21fc30ad100..a43f7aab93bd79 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -119,6 +119,12 @@ def test_add_series_with_extension_array(self, data): def test_error(self): pass + def test_arith_diff_lengths(self, data): + op = self.get_op_from_name('__sub__') + other = data[:3] + with pytest.raises(ValueError): + op(data, other) + def test_direct_arith_with_series_returns_not_implemented(self, data): # Override to use __sub__ instead of __add__ other = pd.Series(data) diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index ea849a78cda122..da269cbb4d0369 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -321,6 +321,17 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators): all_arithmetic_operators ) + def test_arith_diff_lengths(self, data, all_arithmetic_operators): + from pandas.core.dtypes.common import is_float_dtype + + if is_float_dtype(data): + op = self.get_op_from_name(all_arithmetic_operators) + other = data[:3] + with pytest.raises(ValueError): + op(data, other) + else: + pass + class TestComparisonOps(BaseSparseTests, base.BaseComparisonOpsTests): @@ -348,6 +359,17 @@ def _compare_other(self, s, data, op_name, other): result = op(s, other) tm.assert_series_equal(result, expected) + def test_compare_diff_lengths(self, data, all_compare_operators): + from pandas.core.dtypes.common import is_float_dtype + + if is_float_dtype(data): + op = self.get_op_from_name(all_compare_operators) + other = data[:3] + with pytest.raises(ValueError): + op(data, other) + else: + pass + class TestPrinting(BaseSparseTests, base.BasePrintingTests): @pytest.mark.xfail(reason='Different repr', strict=True)