Skip to content

Commit

Permalink
Add test: ValueError raised when operating arrays of diff lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
makbigc committed Dec 18, 2018
1 parent 7939d93 commit 9b0b723
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pandas/tests/extension/base/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
11 changes: 11 additions & 0 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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."""
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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)
6 changes: 6 additions & 0 deletions pandas/tests/extension/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9b0b723

Please sign in to comment.