@@ -341,42 +341,48 @@ def test_logical_with_nas(self):
341
341
expected = Series ([True , True ])
342
342
assert_series_equal (result , expected )
343
343
344
- def test_neg (self ):
345
- numeric = pd .DataFrame ({
346
- 'a' : [- 1 , 0 , 1 ],
347
- 'b' : [1 , 0 , 1 ],
348
- })
349
- boolean = pd .DataFrame ({
350
- 'a' : [True , False , True ],
351
- 'b' : [False , False , True ]
352
- })
353
- timedelta = pd .Series (pd .to_timedelta ([- 1 , 0 , 10 ]))
354
- not_numeric = pd .DataFrame ({'string' : ['a' , 'b' , 'c' ]})
355
- assert_frame_equal (- numeric , - 1 * numeric )
356
- assert_frame_equal (- boolean , ~ boolean )
357
- assert_series_equal (- timedelta , pd .to_timedelta (- 1 * timedelta ))
344
+ @pytest .mark .parametrize ('df,expected' , [
345
+ (pd .DataFrame ({'a' : [- 1 , 1 ]}), pd .DataFrame ({'a' : [1 , - 1 ],})),
346
+ (pd .DataFrame ({'a' : [False , True ]}), pd .DataFrame ({'a' : [True , False ]})),
347
+ (pd .DataFrame ({'a' : pd .Series (pd .to_timedelta ([- 1 , 1 ]))}),
348
+ pd .DataFrame ({'a' : pd .Series (pd .to_timedelta ([1 , - 1 ]))}))
349
+ ])
350
+ def test_neg_numeric (self , df , expected ):
351
+ assert_frame_equal (- df , expected )
352
+ assert_series_equal (- df ['a' ], expected ['a' ])
353
+
354
+ @pytest .mark .parametrize ('df' , [
355
+ pd .DataFrame ({'a' : ['a' , 'b' ]}),
356
+ pd .DataFrame ({'a' : pd .to_datetime (['2017-01-22' , '1970-01-01' ])}),
357
+ ])
358
+ def test_neg_raises (self , df ):
358
359
with pytest .raises (TypeError ):
359
- (+ not_numeric )
360
+ (- df )
361
+ with pytest .raises (TypeError ):
362
+ (- df ['a' ])
360
363
361
364
def test_invert (self ):
362
365
assert_frame_equal (- (self .frame < 0 ), ~ (self .frame < 0 ))
363
366
364
- def test_pos (self ):
365
- numeric = pd .DataFrame ({
366
- 'a' : [- 1 , 0 , 1 ],
367
- 'b' : [1 , 0 , 1 ],
368
- })
369
- boolean = pd .DataFrame ({
370
- 'a' : [True , False , True ],
371
- 'b' : [False , False , True ]
372
- })
373
- timedelta = pd .Series (pd .to_timedelta ([- 1 , 0 , 10 ]))
374
- not_numeric = pd .DataFrame ({'string' : ['a' , 'b' , 'c' ]})
375
- assert_frame_equal (+ numeric , + 1 * numeric )
376
- assert_frame_equal (+ boolean , (+ 1 * boolean ).astype (bool ))
377
- assert_series_equal (+ timedelta , pd .to_timedelta (+ 1 * timedelta ))
367
+ @pytest .mark .parametrize ('df' , [
368
+ pd .DataFrame ({'a' : [- 1 , 1 ]}),
369
+ pd .DataFrame ({'a' : [False , True ]}),
370
+ pd .DataFrame ({'a' : pd .Series (pd .to_timedelta ([- 1 , 1 ]))}),
371
+ ])
372
+ def test_pos_numeric (self , df ):
373
+ # GH 16073
374
+ assert_frame_equal (+ df , df )
375
+ assert_series_equal (+ df ['a' ], df ['a' ])
376
+
377
+ @pytest .mark .parametrize ('df' , [
378
+ pd .DataFrame ({'a' : ['a' , 'b' ]}),
379
+ pd .DataFrame ({'a' : pd .to_datetime (['2017-01-22' , '1970-01-01' ])}),
380
+ ])
381
+ def test_pos_raises (self , df ):
382
+ with pytest .raises (TypeError ):
383
+ (+ df )
378
384
with pytest .raises (TypeError ):
379
- (+ not_numeric )
385
+ (+ df [ 'a' ] )
380
386
381
387
def test_arith_flex_frame (self ):
382
388
ops = ['add' , 'sub' , 'mul' , 'div' , 'truediv' , 'pow' , 'floordiv' , 'mod' ]
0 commit comments