@@ -221,12 +221,13 @@ def test_to_datetime_format_weeks(self, cache):
221221 def test_to_datetime_parse_tzname_or_tzoffset (self , box , const ,
222222 fmt , dates , expected_dates ):
223223 # GH 13486
224- result = pd .to_datetime (dates , format = fmt , box = box )
225- expected = const (expected_dates )
226- tm .assert_equal (result , expected )
224+ with tm .assert_produces_warning (FutureWarning ):
225+ result = pd .to_datetime (dates , format = fmt , box = box )
226+ expected = const (expected_dates )
227+ tm .assert_equal (result , expected )
227228
228- with pytest .raises (ValueError ):
229- pd .to_datetime (dates , format = fmt , box = box , utc = True )
229+ with pytest .raises (ValueError ):
230+ pd .to_datetime (dates , format = fmt , box = box , utc = True )
230231
231232 @pytest .mark .parametrize ('offset' , [
232233 '+0' , '-1foo' , 'UTCbar' , ':10' , '+01:000:01' , '' ])
@@ -256,7 +257,7 @@ def test_to_datetime_dtarr(self, tz):
256257 result = to_datetime (arr )
257258 assert result is arr
258259
259- result = to_datetime (arr , box = True )
260+ result = to_datetime (arr )
260261 assert result is arr
261262
262263 def test_to_datetime_pydatetime (self ):
@@ -364,7 +365,7 @@ def test_to_datetime_array_of_dt64s(self, cache):
364365 # Assuming all datetimes are in bounds, to_datetime() returns
365366 # an array that is equal to Timestamp() parsing
366367 tm .assert_numpy_array_equal (
367- pd .to_datetime (dts , box = False , cache = cache ),
368+ pd .to_datetime (dts , cache = cache ). to_numpy ( ),
368369 np .array ([Timestamp (x ).asm8 for x in dts ])
369370 )
370371
@@ -376,8 +377,8 @@ def test_to_datetime_array_of_dt64s(self, cache):
376377 pd .to_datetime (dts_with_oob , errors = 'raise' )
377378
378379 tm .assert_numpy_array_equal (
379- pd .to_datetime (dts_with_oob , box = False , errors = 'coerce' ,
380- cache = cache ),
380+ pd .to_datetime (dts_with_oob , errors = 'coerce' ,
381+ cache = cache ). to_numpy () ,
381382 np .array (
382383 [
383384 Timestamp (dts_with_oob [0 ]).asm8 ,
@@ -392,8 +393,8 @@ def test_to_datetime_array_of_dt64s(self, cache):
392393 # are converted to their .item(), which depending on the version of
393394 # numpy is either a python datetime.datetime or datetime.date
394395 tm .assert_numpy_array_equal (
395- pd .to_datetime (dts_with_oob , box = False , errors = 'ignore' ,
396- cache = cache ),
396+ pd .to_datetime (dts_with_oob , errors = 'ignore' ,
397+ cache = cache ). to_numpy () ,
397398 np .array (
398399 [dt .item () for dt in dts_with_oob ],
399400 dtype = 'O'
@@ -628,10 +629,14 @@ def test_to_datetime_cache(self, utc, format, box, constructor):
628629 date = '20130101 00:00:00'
629630 test_dates = [date ] * 10 ** 5
630631 data = constructor (test_dates )
631- result = pd .to_datetime (data , utc = utc , format = format , box = box ,
632- cache = True )
633- expected = pd .to_datetime (data , utc = utc , format = format , box = box ,
634- cache = False )
632+
633+ with tm .assert_produces_warning (FutureWarning ):
634+ result = pd .to_datetime (data , utc = utc , format = format , box = box ,
635+ cache = True )
636+
637+ with tm .assert_produces_warning (FutureWarning ):
638+ expected = pd .to_datetime (data , utc = utc , format = format , box = box ,
639+ cache = False )
635640 if box :
636641 tm .assert_index_equal (result , expected )
637642 else :
@@ -684,7 +689,10 @@ def test_iso_8601_strings_with_same_offset(self):
684689 def test_iso_8601_strings_same_offset_no_box (self ):
685690 # GH 22446
686691 data = ['2018-01-04 09:01:00+09:00' , '2018-01-04 09:02:00+09:00' ]
687- result = pd .to_datetime (data , box = False )
692+
693+ with tm .assert_produces_warning (FutureWarning ):
694+ result = pd .to_datetime (data , box = False )
695+
688696 expected = np .array ([
689697 datetime (2018 , 1 , 4 , 9 , 1 , tzinfo = pytz .FixedOffset (540 )),
690698 datetime (2018 , 1 , 4 , 9 , 2 , tzinfo = pytz .FixedOffset (540 ))
@@ -753,6 +761,16 @@ def test_timestamp_utc_true(self, ts, expected):
753761 result = to_datetime (ts , utc = True )
754762 assert result == expected
755763
764+ def test_to_datetime_box_deprecated (self ):
765+ expected = np .datetime64 ('2018-09-09' )
766+
767+ # Deprecated - see GH24416
768+ with tm .assert_produces_warning (FutureWarning ):
769+ pd .to_datetime (expected , box = False )
770+
771+ result = pd .to_datetime (expected ).to_datetime64 ()
772+ assert result == expected
773+
756774
757775class TestToDatetimeUnit (object ):
758776 @pytest .mark .parametrize ('cache' , [True , False ])
@@ -891,7 +909,7 @@ def test_unit_rounding(self, cache):
891909 def test_unit_ignore_keeps_name (self , cache ):
892910 # GH 21697
893911 expected = pd .Index ([15e9 ] * 2 , name = 'name' )
894- result = pd .to_datetime (expected , errors = 'ignore' , box = True , unit = 's' ,
912+ result = pd .to_datetime (expected , errors = 'ignore' , unit = 's' ,
895913 cache = cache )
896914 tm .assert_index_equal (result , expected )
897915
@@ -1052,7 +1070,10 @@ def test_dataframe_box_false(self):
10521070 df = pd .DataFrame ({'year' : [2015 , 2016 ],
10531071 'month' : [2 , 3 ],
10541072 'day' : [4 , 5 ]})
1055- result = pd .to_datetime (df , box = False )
1073+
1074+ with tm .assert_produces_warning (FutureWarning ):
1075+ result = pd .to_datetime (df , box = False )
1076+
10561077 expected = np .array (['2015-02-04' , '2016-03-05' ],
10571078 dtype = 'datetime64[ns]' )
10581079 tm .assert_numpy_array_equal (result , expected )
@@ -1069,8 +1090,7 @@ def test_dataframe_utc_true(self):
10691090
10701091 def test_to_datetime_errors_ignore_utc_true (self ):
10711092 # GH 23758
1072- result = pd .to_datetime ([1 ], unit = 's' , box = True , utc = True ,
1073- errors = 'ignore' )
1093+ result = pd .to_datetime ([1 ], unit = 's' , utc = True , errors = 'ignore' )
10741094 expected = DatetimeIndex (['1970-01-01 00:00:01' ], tz = 'UTC' )
10751095 tm .assert_index_equal (result , expected )
10761096
@@ -1195,11 +1215,15 @@ def test_to_datetime_types(self, cache):
11951215 def test_to_datetime_unprocessable_input (self , cache , box , klass ):
11961216 # GH 4928
11971217 # GH 21864
1198- result = to_datetime ([1 , '1' ], errors = 'ignore' , cache = cache , box = box )
1218+ with tm .assert_produces_warning (FutureWarning ):
1219+ result = to_datetime ([1 , '1' ], errors = 'ignore' , cache = cache ,
1220+ box = box )
1221+
11991222 expected = klass (np .array ([1 , '1' ], dtype = 'O' ))
12001223 tm .assert_equal (result , expected )
12011224 msg = "invalid string coercion to datetime"
1202- with pytest .raises (TypeError , match = msg ):
1225+ with (pytest .raises (TypeError , match = msg ),
1226+ tm .assert_produces_warning (FutureWarning )):
12031227 to_datetime ([1 , '1' ], errors = 'raise' , cache = cache , box = box )
12041228
12051229 def test_to_datetime_other_datetime64_units (self ):
0 commit comments