@@ -221,12 +221,13 @@ def test_to_datetime_format_weeks(self, cache):
221
221
def test_to_datetime_parse_tzname_or_tzoffset (self , box , const ,
222
222
fmt , dates , expected_dates ):
223
223
# 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 )
227
228
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 )
230
231
231
232
@pytest .mark .parametrize ('offset' , [
232
233
'+0' , '-1foo' , 'UTCbar' , ':10' , '+01:000:01' , '' ])
@@ -256,7 +257,7 @@ def test_to_datetime_dtarr(self, tz):
256
257
result = to_datetime (arr )
257
258
assert result is arr
258
259
259
- result = to_datetime (arr , box = True )
260
+ result = to_datetime (arr )
260
261
assert result is arr
261
262
262
263
def test_to_datetime_pydatetime (self ):
@@ -364,7 +365,7 @@ def test_to_datetime_array_of_dt64s(self, cache):
364
365
# Assuming all datetimes are in bounds, to_datetime() returns
365
366
# an array that is equal to Timestamp() parsing
366
367
tm .assert_numpy_array_equal (
367
- pd .to_datetime (dts , box = False , cache = cache ),
368
+ pd .to_datetime (dts , cache = cache ). to_numpy ( ),
368
369
np .array ([Timestamp (x ).asm8 for x in dts ])
369
370
)
370
371
@@ -376,8 +377,8 @@ def test_to_datetime_array_of_dt64s(self, cache):
376
377
pd .to_datetime (dts_with_oob , errors = 'raise' )
377
378
378
379
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 () ,
381
382
np .array (
382
383
[
383
384
Timestamp (dts_with_oob [0 ]).asm8 ,
@@ -392,8 +393,8 @@ def test_to_datetime_array_of_dt64s(self, cache):
392
393
# are converted to their .item(), which depending on the version of
393
394
# numpy is either a python datetime.datetime or datetime.date
394
395
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 () ,
397
398
np .array (
398
399
[dt .item () for dt in dts_with_oob ],
399
400
dtype = 'O'
@@ -628,10 +629,14 @@ def test_to_datetime_cache(self, utc, format, box, constructor):
628
629
date = '20130101 00:00:00'
629
630
test_dates = [date ] * 10 ** 5
630
631
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 )
635
640
if box :
636
641
tm .assert_index_equal (result , expected )
637
642
else :
@@ -684,7 +689,10 @@ def test_iso_8601_strings_with_same_offset(self):
684
689
def test_iso_8601_strings_same_offset_no_box (self ):
685
690
# GH 22446
686
691
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
+
688
696
expected = np .array ([
689
697
datetime (2018 , 1 , 4 , 9 , 1 , tzinfo = pytz .FixedOffset (540 )),
690
698
datetime (2018 , 1 , 4 , 9 , 2 , tzinfo = pytz .FixedOffset (540 ))
@@ -753,6 +761,16 @@ def test_timestamp_utc_true(self, ts, expected):
753
761
result = to_datetime (ts , utc = True )
754
762
assert result == expected
755
763
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
+
756
774
757
775
class TestToDatetimeUnit (object ):
758
776
@pytest .mark .parametrize ('cache' , [True , False ])
@@ -891,7 +909,7 @@ def test_unit_rounding(self, cache):
891
909
def test_unit_ignore_keeps_name (self , cache ):
892
910
# GH 21697
893
911
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' ,
895
913
cache = cache )
896
914
tm .assert_index_equal (result , expected )
897
915
@@ -1052,7 +1070,10 @@ def test_dataframe_box_false(self):
1052
1070
df = pd .DataFrame ({'year' : [2015 , 2016 ],
1053
1071
'month' : [2 , 3 ],
1054
1072
'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
+
1056
1077
expected = np .array (['2015-02-04' , '2016-03-05' ],
1057
1078
dtype = 'datetime64[ns]' )
1058
1079
tm .assert_numpy_array_equal (result , expected )
@@ -1069,8 +1090,7 @@ def test_dataframe_utc_true(self):
1069
1090
1070
1091
def test_to_datetime_errors_ignore_utc_true (self ):
1071
1092
# 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' )
1074
1094
expected = DatetimeIndex (['1970-01-01 00:00:01' ], tz = 'UTC' )
1075
1095
tm .assert_index_equal (result , expected )
1076
1096
@@ -1195,11 +1215,15 @@ def test_to_datetime_types(self, cache):
1195
1215
def test_to_datetime_unprocessable_input (self , cache , box , klass ):
1196
1216
# GH 4928
1197
1217
# 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
+
1199
1222
expected = klass (np .array ([1 , '1' ], dtype = 'O' ))
1200
1223
tm .assert_equal (result , expected )
1201
1224
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 )):
1203
1227
to_datetime ([1 , '1' ], errors = 'raise' , cache = cache , box = box )
1204
1228
1205
1229
def test_to_datetime_other_datetime64_units (self ):
0 commit comments