Skip to content

Commit c61a108

Browse files
committed
TST: paramterizes pos and neg tests
1 parent 2c08cdb commit c61a108

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

pandas/tests/frame/test_operators.py

+36-30
Original file line numberDiff line numberDiff line change
@@ -388,42 +388,48 @@ def test_logical_with_nas(self):
388388
expected = Series([True, True])
389389
assert_series_equal(result, expected)
390390

391-
def test_neg(self):
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))
391+
@pytest.mark.parametrize('df,expected', [
392+
(pd.DataFrame({'a': [-1, 1]}), pd.DataFrame({'a': [1, -1],})),
393+
(pd.DataFrame({'a': [False, True]}), pd.DataFrame({'a': [True, False]})),
394+
(pd.DataFrame({'a': pd.Series(pd.to_timedelta([-1, 1]))}),
395+
pd.DataFrame({'a': pd.Series(pd.to_timedelta([1, -1]))}))
396+
])
397+
def test_neg_numeric(self, df, expected):
398+
assert_frame_equal(-df, expected)
399+
assert_series_equal(-df['a'], expected['a'])
400+
401+
@pytest.mark.parametrize('df', [
402+
pd.DataFrame({'a': ['a', 'b']}),
403+
pd.DataFrame({'a': pd.to_datetime(['2017-01-22', '1970-01-01'])}),
404+
])
405+
def test_neg_raises(self, df):
405406
with pytest.raises(TypeError):
406-
(+ not_numeric)
407+
(- df)
408+
with pytest.raises(TypeError):
409+
(- df['a'])
407410

408411
def test_invert(self):
409412
assert_frame_equal(-(self.frame < 0), ~(self.frame < 0))
410413

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))
414+
@pytest.mark.parametrize('df', [
415+
pd.DataFrame({'a': [-1, 1]}),
416+
pd.DataFrame({'a': [False, True]}),
417+
pd.DataFrame({'a': pd.Series(pd.to_timedelta([-1, 1]))}),
418+
])
419+
def test_pos_numeric(self, df):
420+
# GH 16073
421+
assert_frame_equal(+df, df)
422+
assert_series_equal(+df['a'], df['a'])
423+
424+
@pytest.mark.parametrize('df', [
425+
pd.DataFrame({'a': ['a', 'b']}),
426+
pd.DataFrame({'a': pd.to_datetime(['2017-01-22', '1970-01-01'])}),
427+
])
428+
def test_pos_raises(self, df):
429+
with pytest.raises(TypeError):
430+
(+ df)
425431
with pytest.raises(TypeError):
426-
(+ not_numeric)
432+
(+ df['a'])
427433

428434
def test_arith_flex_frame(self):
429435
ops = ['add', 'sub', 'mul', 'div', 'truediv', 'pow', 'floordiv', 'mod']

0 commit comments

Comments
 (0)