@@ -6452,35 +6452,41 @@ def test_apply_dont_convert_dtype(self):
6452
6452
def test_convert_objects (self ):
6453
6453
6454
6454
s = Series ([1. , 2 , 3 ], index = ['a' , 'b' , 'c' ])
6455
- result = s .convert_objects (convert_dates = False , convert_numeric = True )
6455
+ with tm .assert_produces_warning (FutureWarning ):
6456
+ result = s .convert_objects (convert_dates = False , convert_numeric = True )
6456
6457
assert_series_equal (result , s )
6457
6458
6458
6459
# force numeric conversion
6459
6460
r = s .copy ().astype ('O' )
6460
6461
r ['a' ] = '1'
6461
- result = r .convert_objects (convert_dates = False , convert_numeric = True )
6462
+ with tm .assert_produces_warning (FutureWarning ):
6463
+ result = r .convert_objects (convert_dates = False , convert_numeric = True )
6462
6464
assert_series_equal (result , s )
6463
6465
6464
6466
r = s .copy ().astype ('O' )
6465
6467
r ['a' ] = '1.'
6466
- result = r .convert_objects (convert_dates = False , convert_numeric = True )
6468
+ with tm .assert_produces_warning (FutureWarning ):
6469
+ result = r .convert_objects (convert_dates = False , convert_numeric = True )
6467
6470
assert_series_equal (result , s )
6468
6471
6469
6472
r = s .copy ().astype ('O' )
6470
6473
r ['a' ] = 'garbled'
6471
6474
expected = s .copy ()
6472
6475
expected ['a' ] = np .nan
6473
- result = r .convert_objects (convert_dates = False , convert_numeric = True )
6476
+ with tm .assert_produces_warning (FutureWarning ):
6477
+ result = r .convert_objects (convert_dates = False , convert_numeric = True )
6474
6478
assert_series_equal (result , expected )
6475
6479
6476
6480
# GH 4119, not converting a mixed type (e.g.floats and object)
6477
6481
s = Series ([1 , 'na' , 3 , 4 ])
6478
- result = s .convert_objects (convert_numeric = True )
6482
+ with tm .assert_produces_warning (FutureWarning ):
6483
+ result = s .convert_objects (convert_numeric = True )
6479
6484
expected = Series ([1 , np .nan , 3 , 4 ])
6480
6485
assert_series_equal (result , expected )
6481
6486
6482
6487
s = Series ([1 , '' , 3 , 4 ])
6483
- result = s .convert_objects (convert_numeric = True )
6488
+ with tm .assert_produces_warning (FutureWarning ):
6489
+ result = s .convert_objects (convert_numeric = True )
6484
6490
expected = Series ([1 , np .nan , 3 , 4 ])
6485
6491
assert_series_equal (result , expected )
6486
6492
@@ -6489,39 +6495,45 @@ def test_convert_objects(self):
6489
6495
[datetime (2001 , 1 , 1 , 0 , 0 ), datetime (2001 , 1 , 2 , 0 , 0 ), datetime (2001 , 1 , 3 , 0 , 0 )])
6490
6496
s2 = Series ([datetime (2001 , 1 , 1 , 0 , 0 ), datetime (2001 , 1 , 2 , 0 , 0 ), datetime (
6491
6497
2001 , 1 , 3 , 0 , 0 ), 'foo' , 1.0 , 1 , Timestamp ('20010104' ), '20010105' ], dtype = 'O' )
6492
-
6493
- result = s .convert_objects (convert_dates = True , convert_numeric = False )
6498
+ with tm . assert_produces_warning ( FutureWarning ):
6499
+ result = s .convert_objects (convert_dates = True , convert_numeric = False )
6494
6500
expected = Series (
6495
6501
[Timestamp ('20010101' ), Timestamp ('20010102' ), Timestamp ('20010103' )], dtype = 'M8[ns]' )
6496
6502
assert_series_equal (result , expected )
6497
6503
6498
- result = s .convert_objects (
6499
- convert_dates = 'coerce' , convert_numeric = False )
6500
- result = s .convert_objects (
6501
- convert_dates = 'coerce' , convert_numeric = True )
6504
+ with tm .assert_produces_warning (FutureWarning ):
6505
+ result = s .convert_objects (convert_dates = 'coerce' ,
6506
+ convert_numeric = False )
6507
+ with tm .assert_produces_warning (FutureWarning ):
6508
+ result = s .convert_objects (convert_dates = 'coerce' ,
6509
+ convert_numeric = True )
6502
6510
assert_series_equal (result , expected )
6503
6511
6504
6512
expected = Series (
6505
6513
[Timestamp (
6506
6514
'20010101' ), Timestamp ('20010102' ), Timestamp ('20010103' ),
6507
6515
lib .NaT , lib .NaT , lib .NaT , Timestamp ('20010104' ), Timestamp ('20010105' )], dtype = 'M8[ns]' )
6508
- result = s2 .convert_objects (
6509
- convert_dates = 'coerce' , convert_numeric = False )
6516
+ with tm .assert_produces_warning (FutureWarning ):
6517
+ result = s2 .convert_objects (convert_dates = 'coerce' ,
6518
+ convert_numeric = False )
6510
6519
assert_series_equal (result , expected )
6511
- result = s2 .convert_objects (
6512
- convert_dates = 'coerce' , convert_numeric = True )
6520
+ with tm .assert_produces_warning (FutureWarning ):
6521
+ result = s2 .convert_objects (convert_dates = 'coerce' ,
6522
+ convert_numeric = True )
6513
6523
assert_series_equal (result , expected )
6514
6524
6515
6525
# preserver all-nans (if convert_dates='coerce')
6516
6526
s = Series (['foo' , 'bar' , 1 , 1.0 ], dtype = 'O' )
6517
- result = s .convert_objects (
6518
- convert_dates = 'coerce' , convert_numeric = False )
6527
+ with tm .assert_produces_warning (FutureWarning ):
6528
+ result = s .convert_objects (convert_dates = 'coerce' ,
6529
+ convert_numeric = False )
6519
6530
assert_series_equal (result , s )
6520
6531
6521
6532
# preserver if non-object
6522
6533
s = Series ([1 ], dtype = 'float32' )
6523
- result = s .convert_objects (
6524
- convert_dates = 'coerce' , convert_numeric = False )
6534
+ with tm .assert_produces_warning (FutureWarning ):
6535
+ result = s .convert_objects (convert_dates = 'coerce' ,
6536
+ convert_numeric = False )
6525
6537
assert_series_equal (result , s )
6526
6538
6527
6539
#r = s.copy()
@@ -6532,21 +6544,25 @@ def test_convert_objects(self):
6532
6544
# dateutil parses some single letters into today's value as a date
6533
6545
for x in 'abcdefghijklmnopqrstuvwxyz' :
6534
6546
s = Series ([x ])
6535
- result = s .convert_objects (convert_dates = 'coerce' )
6547
+ with tm .assert_produces_warning (FutureWarning ):
6548
+ result = s .convert_objects (convert_dates = 'coerce' )
6536
6549
assert_series_equal (result , s )
6537
6550
s = Series ([x .upper ()])
6538
- result = s .convert_objects (convert_dates = 'coerce' )
6551
+ with tm .assert_produces_warning (FutureWarning ):
6552
+ result = s .convert_objects (convert_dates = 'coerce' )
6539
6553
assert_series_equal (result , s )
6540
6554
6541
6555
def test_convert_objects_preserve_bool (self ):
6542
6556
s = Series ([1 , True , 3 , 5 ], dtype = object )
6543
- r = s .convert_objects (convert_numeric = True )
6557
+ with tm .assert_produces_warning (FutureWarning ):
6558
+ r = s .convert_objects (convert_numeric = True )
6544
6559
e = Series ([1 , 1 , 3 , 5 ], dtype = 'i8' )
6545
6560
tm .assert_series_equal (r , e )
6546
6561
6547
6562
def test_convert_objects_preserve_all_bool (self ):
6548
6563
s = Series ([False , True , False , False ], dtype = object )
6549
- r = s .convert_objects (convert_numeric = True )
6564
+ with tm .assert_produces_warning (FutureWarning ):
6565
+ r = s .convert_objects (convert_numeric = True )
6550
6566
e = Series ([False , True , False , False ], dtype = bool )
6551
6567
tm .assert_series_equal (r , e )
6552
6568
0 commit comments