@@ -271,42 +271,48 @@ def test_logical_with_nas(self):
271
271
expected = Series ([True , True ])
272
272
assert_series_equal (result , expected )
273
273
274
- def test_neg (self ):
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 ))
274
+ @pytest .mark .parametrize ('df,expected' , [
275
+ (pd .DataFrame ({'a' : [- 1 , 1 ]}), pd .DataFrame ({'a' : [1 , - 1 ],})),
276
+ (pd .DataFrame ({'a' : [False , True ]}), pd .DataFrame ({'a' : [True , False ]})),
277
+ (pd .DataFrame ({'a' : pd .Series (pd .to_timedelta ([- 1 , 1 ]))}),
278
+ pd .DataFrame ({'a' : pd .Series (pd .to_timedelta ([1 , - 1 ]))}))
279
+ ])
280
+ def test_neg_numeric (self , df , expected ):
281
+ assert_frame_equal (- df , expected )
282
+ assert_series_equal (- df ['a' ], expected ['a' ])
283
+
284
+ @pytest .mark .parametrize ('df' , [
285
+ pd .DataFrame ({'a' : ['a' , 'b' ]}),
286
+ pd .DataFrame ({'a' : pd .to_datetime (['2017-01-22' , '1970-01-01' ])}),
287
+ ])
288
+ def test_neg_raises (self , df ):
288
289
with pytest .raises (TypeError ):
289
- (+ not_numeric )
290
+ (- df )
291
+ with pytest .raises (TypeError ):
292
+ (- df ['a' ])
290
293
291
294
def test_invert (self ):
292
295
assert_frame_equal (- (self .frame < 0 ), ~ (self .frame < 0 ))
293
296
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 ))
297
+ @pytest .mark .parametrize ('df' , [
298
+ pd .DataFrame ({'a' : [- 1 , 1 ]}),
299
+ pd .DataFrame ({'a' : [False , True ]}),
300
+ pd .DataFrame ({'a' : pd .Series (pd .to_timedelta ([- 1 , 1 ]))}),
301
+ ])
302
+ def test_pos_numeric (self , df ):
303
+ # GH 16073
304
+ assert_frame_equal (+ df , df )
305
+ assert_series_equal (+ df ['a' ], df ['a' ])
306
+
307
+ @pytest .mark .parametrize ('df' , [
308
+ pd .DataFrame ({'a' : ['a' , 'b' ]}),
309
+ pd .DataFrame ({'a' : pd .to_datetime (['2017-01-22' , '1970-01-01' ])}),
310
+ ])
311
+ def test_pos_raises (self , df ):
312
+ with pytest .raises (TypeError ):
313
+ (+ df )
308
314
with pytest .raises (TypeError ):
309
- (+ not_numeric )
315
+ (+ df [ 'a' ] )
310
316
311
317
def test_arith_flex_frame (self ):
312
318
ops = ['add' , 'sub' , 'mul' , 'div' , 'truediv' , 'pow' , 'floordiv' , 'mod' ]
0 commit comments