@@ -388,42 +388,48 @@ def test_logical_with_nas(self):
388
388
expected = Series ([True , True ])
389
389
assert_series_equal (result , expected )
390
390
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 ):
405
406
with pytest .raises (TypeError ):
406
- (+ not_numeric )
407
+ (- df )
408
+ with pytest .raises (TypeError ):
409
+ (- df ['a' ])
407
410
408
411
def test_invert (self ):
409
412
assert_frame_equal (- (self .frame < 0 ), ~ (self .frame < 0 ))
410
413
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 )
425
431
with pytest .raises (TypeError ):
426
- (+ not_numeric )
432
+ (+ df [ 'a' ] )
427
433
428
434
def test_arith_flex_frame (self ):
429
435
ops = ['add' , 'sub' , 'mul' , 'div' , 'truediv' , 'pow' , 'floordiv' , 'mod' ]
0 commit comments