@@ -6452,35 +6452,41 @@ def test_apply_dont_convert_dtype(self):
64526452 def test_convert_objects (self ):
64536453
64546454 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 )
64566457 assert_series_equal (result , s )
64576458
64586459 # force numeric conversion
64596460 r = s .copy ().astype ('O' )
64606461 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 )
64626464 assert_series_equal (result , s )
64636465
64646466 r = s .copy ().astype ('O' )
64656467 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 )
64676470 assert_series_equal (result , s )
64686471
64696472 r = s .copy ().astype ('O' )
64706473 r ['a' ] = 'garbled'
64716474 expected = s .copy ()
64726475 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 )
64746478 assert_series_equal (result , expected )
64756479
64766480 # GH 4119, not converting a mixed type (e.g.floats and object)
64776481 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 )
64796484 expected = Series ([1 , np .nan , 3 , 4 ])
64806485 assert_series_equal (result , expected )
64816486
64826487 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 )
64846490 expected = Series ([1 , np .nan , 3 , 4 ])
64856491 assert_series_equal (result , expected )
64866492
@@ -6489,39 +6495,45 @@ def test_convert_objects(self):
64896495 [datetime (2001 , 1 , 1 , 0 , 0 ), datetime (2001 , 1 , 2 , 0 , 0 ), datetime (2001 , 1 , 3 , 0 , 0 )])
64906496 s2 = Series ([datetime (2001 , 1 , 1 , 0 , 0 ), datetime (2001 , 1 , 2 , 0 , 0 ), datetime (
64916497 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 )
64946500 expected = Series (
64956501 [Timestamp ('20010101' ), Timestamp ('20010102' ), Timestamp ('20010103' )], dtype = 'M8[ns]' )
64966502 assert_series_equal (result , expected )
64976503
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 )
65026510 assert_series_equal (result , expected )
65036511
65046512 expected = Series (
65056513 [Timestamp (
65066514 '20010101' ), Timestamp ('20010102' ), Timestamp ('20010103' ),
65076515 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 )
65106519 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 )
65136523 assert_series_equal (result , expected )
65146524
65156525 # preserver all-nans (if convert_dates='coerce')
65166526 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 )
65196530 assert_series_equal (result , s )
65206531
65216532 # preserver if non-object
65226533 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 )
65256537 assert_series_equal (result , s )
65266538
65276539 #r = s.copy()
@@ -6532,21 +6544,25 @@ def test_convert_objects(self):
65326544 # dateutil parses some single letters into today's value as a date
65336545 for x in 'abcdefghijklmnopqrstuvwxyz' :
65346546 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' )
65366549 assert_series_equal (result , s )
65376550 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' )
65396553 assert_series_equal (result , s )
65406554
65416555 def test_convert_objects_preserve_bool (self ):
65426556 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 )
65446559 e = Series ([1 , 1 , 3 , 5 ], dtype = 'i8' )
65456560 tm .assert_series_equal (r , e )
65466561
65476562 def test_convert_objects_preserve_all_bool (self ):
65486563 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 )
65506566 e = Series ([False , True , False , False ], dtype = bool )
65516567 tm .assert_series_equal (r , e )
65526568
0 commit comments