Skip to content

Commit 6b9d5c3

Browse files
committed
TST: adds tests for unary plus and unary neg
1 parent 9a744a7 commit 6b9d5c3

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

pandas/tests/frame/test_operators.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,42 @@ def test_logical_with_nas(self):
389389
assert_series_equal(result, expected)
390390

391391
def test_neg(self):
392-
# what to do?
393-
assert_frame_equal(-self.frame, -1 * self.frame)
392+
numeric = pd.DataFrame({
393+
'a': [-1, 0, 1],
394+
'b': [1, 0, 1],
395+
})
396+
boolean = pd.DataFrame({
397+
'a': [True, False, True],
398+
'b': [False, False, True]
399+
})
400+
timedelta = pd.Series(pd.to_timedelta([-1, 0, 10]))
401+
not_numeric = pd.DataFrame({'string': ['a', 'b', 'c']})
402+
assert_frame_equal(-numeric, -1 * numeric)
403+
assert_frame_equal(-boolean, ~boolean)
404+
assert_series_equal(-timedelta, pd.to_timedelta(-1 * timedelta))
405+
with pytest.raises(TypeError):
406+
(+ not_numeric)
394407

395408
def test_invert(self):
396409
assert_frame_equal(-(self.frame < 0), ~(self.frame < 0))
397410

411+
def test_pos(self):
412+
numeric = pd.DataFrame({
413+
'a': [-1, 0, 1],
414+
'b': [1, 0, 1],
415+
})
416+
boolean = pd.DataFrame({
417+
'a': [True, False, True],
418+
'b': [False, False, True]
419+
})
420+
timedelta = pd.Series(pd.to_timedelta([-1, 0, 10]))
421+
not_numeric = pd.DataFrame({'string': ['a', 'b', 'c']})
422+
assert_frame_equal(+numeric, +1 * numeric)
423+
assert_frame_equal(+boolean, (+1 * boolean).astype(bool))
424+
assert_series_equal(+timedelta, pd.to_timedelta(+1 * timedelta))
425+
with pytest.raises(TypeError):
426+
(+ not_numeric)
427+
398428
def test_arith_flex_frame(self):
399429
ops = ['add', 'sub', 'mul', 'div', 'truediv', 'pow', 'floordiv', 'mod']
400430
if not compat.PY3:

0 commit comments

Comments
 (0)