Skip to content

Commit 8429618

Browse files
committed
TST: adds tests for unary plus and unary neg
1 parent b018715 commit 8429618

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
@@ -272,12 +272,42 @@ def test_logical_with_nas(self):
272272
assert_series_equal(result, expected)
273273

274274
def test_neg(self):
275-
# what to do?
276-
assert_frame_equal(-self.frame, -1 * self.frame)
275+
numeric = pd.DataFrame({
276+
'a': [-1, 0, 1],
277+
'b': [1, 0, 1],
278+
})
279+
boolean = pd.DataFrame({
280+
'a': [True, False, True],
281+
'b': [False, False, True]
282+
})
283+
timedelta = pd.Series(pd.to_timedelta([-1, 0, 10]))
284+
not_numeric = pd.DataFrame({'string': ['a', 'b', 'c']})
285+
assert_frame_equal(-numeric, -1 * numeric)
286+
assert_frame_equal(-boolean, ~boolean)
287+
assert_series_equal(-timedelta, pd.to_timedelta(-1 * timedelta))
288+
with pytest.raises(TypeError):
289+
(+ not_numeric)
277290

278291
def test_invert(self):
279292
assert_frame_equal(-(self.frame < 0), ~(self.frame < 0))
280293

294+
def test_pos(self):
295+
numeric = pd.DataFrame({
296+
'a': [-1, 0, 1],
297+
'b': [1, 0, 1],
298+
})
299+
boolean = pd.DataFrame({
300+
'a': [True, False, True],
301+
'b': [False, False, True]
302+
})
303+
timedelta = pd.Series(pd.to_timedelta([-1, 0, 10]))
304+
not_numeric = pd.DataFrame({'string': ['a', 'b', 'c']})
305+
assert_frame_equal(+numeric, +1 * numeric)
306+
assert_frame_equal(+boolean, (+1 * boolean).astype(bool))
307+
assert_series_equal(+timedelta, pd.to_timedelta(+1 * timedelta))
308+
with pytest.raises(TypeError):
309+
(+ not_numeric)
310+
281311
def test_arith_flex_frame(self):
282312
ops = ['add', 'sub', 'mul', 'div', 'truediv', 'pow', 'floordiv', 'mod']
283313
if not compat.PY3:

0 commit comments

Comments
 (0)