Skip to content

Commit 9b0b723

Browse files
committed
Add test: ValueError raised when operating arrays of diff lengths
1 parent 7939d93 commit 9b0b723

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

pandas/tests/extension/base/ops.py

+12
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ def test_direct_arith_with_series_returns_not_implemented(self, data):
119119
"{} does not implement add".format(data.__class__.__name__)
120120
)
121121

122+
def test_arith_diff_lengths(self, data, all_arithmetic_operators):
123+
op = self.get_op_from_name(all_arithmetic_operators)
124+
other = data[:3]
125+
with pytest.raises(ValueError):
126+
op(data, other)
127+
122128

123129
class BaseComparisonOpsTests(BaseOpsUtil):
124130
"""Various Series and DataFrame comparison ops methods."""
@@ -164,3 +170,9 @@ def test_direct_arith_with_series_returns_not_implemented(self, data):
164170
raise pytest.skip(
165171
"{} does not implement __eq__".format(data.__class__.__name__)
166172
)
173+
174+
def test_compare_diff_lengths(self, data, all_compare_operators):
175+
op = self.get_op_from_name(all_compare_operators)
176+
other = data[:3]
177+
with pytest.raises(ValueError):
178+
op(data, other)

pandas/tests/extension/decimal/test_decimal.py

+11
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ def _check_divmod_op(self, s, op, other, exc=NotImplementedError):
299299
def test_error(self):
300300
pass
301301

302+
def test_arith_diff_lengths(self):
303+
# TODO
304+
# Raise ValueError when carrying out arithmetic operation
305+
# on two decimal arrays of different lengths
306+
pass
307+
302308

303309
class TestComparisonOps(BaseDecimal, base.BaseComparisonOpsTests):
304310

@@ -324,6 +330,11 @@ def test_compare_array(self, data, all_compare_operators):
324330
for i in alter]
325331
self._compare_other(s, data, op_name, other)
326332

333+
def test_compare_diff_lengths(self):
334+
# TODO:
335+
# Raise ValueError when comparing decimal arrays of different lenghts
336+
pass
337+
327338

328339
class DecimalArrayWithoutFromSequence(DecimalArray):
329340
"""Helper class for testing error handling in _from_sequence."""

pandas/tests/extension/json/test_json.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,13 @@ def _check_divmod_op(self, s, op, other, exc=NotImplementedError):
291291
s, op, other, exc=TypeError
292292
)
293293

294+
def test_arith_diff_lengths(self):
295+
pass
296+
294297

295298
class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests):
296-
pass
299+
def test_compare_diff_lengths(self):
300+
pass
297301

298302

299303
class TestPrinting(BaseJSON, base.BasePrintingTests):

pandas/tests/extension/test_categorical.py

+11
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ def _check_divmod_op(self, s, op, other, exc=NotImplementedError):
215215
s, op, other, exc=TypeError
216216
)
217217

218+
def test_arith_diff_lengths(self):
219+
pass
220+
218221

219222
class TestComparisonOps(base.BaseComparisonOpsTests):
220223

@@ -233,3 +236,11 @@ def _compare_other(self, s, data, op_name, other):
233236
else:
234237
with pytest.raises(TypeError):
235238
op(data, other)
239+
240+
@pytest.mark.parametrize('op_name',
241+
['__eq__', '__ne__'])
242+
def test_compare_diff_lengths(self, data, op_name):
243+
op = self.get_op_from_name(op_name)
244+
other = data[:3]
245+
with pytest.raises(ValueError):
246+
op(data, other)

pandas/tests/extension/test_period.py

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ def test_add_series_with_extension_array(self, data):
119119
def test_error(self):
120120
pass
121121

122+
def test_arith_diff_lengths(self, data):
123+
op = self.get_op_from_name('__sub__')
124+
other = data[:3]
125+
with pytest.raises(ValueError):
126+
op(data, other)
127+
122128
def test_direct_arith_with_series_returns_not_implemented(self, data):
123129
# Override to use __sub__ instead of __add__
124130
other = pd.Series(data)

pandas/tests/extension/test_sparse.py

+22
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators):
321321
all_arithmetic_operators
322322
)
323323

324+
def test_arith_diff_lengths(self, data, all_arithmetic_operators):
325+
from pandas.core.dtypes.common import is_float_dtype
326+
327+
if is_float_dtype(data):
328+
op = self.get_op_from_name(all_arithmetic_operators)
329+
other = data[:3]
330+
with pytest.raises(ValueError):
331+
op(data, other)
332+
else:
333+
pass
334+
324335

325336
class TestComparisonOps(BaseSparseTests, base.BaseComparisonOpsTests):
326337

@@ -348,6 +359,17 @@ def _compare_other(self, s, data, op_name, other):
348359
result = op(s, other)
349360
tm.assert_series_equal(result, expected)
350361

362+
def test_compare_diff_lengths(self, data, all_compare_operators):
363+
from pandas.core.dtypes.common import is_float_dtype
364+
365+
if is_float_dtype(data):
366+
op = self.get_op_from_name(all_compare_operators)
367+
other = data[:3]
368+
with pytest.raises(ValueError):
369+
op(data, other)
370+
else:
371+
pass
372+
351373

352374
class TestPrinting(BaseSparseTests, base.BasePrintingTests):
353375
@pytest.mark.xfail(reason='Different repr', strict=True)

0 commit comments

Comments
 (0)