@@ -184,9 +184,6 @@ def test_to_datetime_format_weeks(self, cache):
184
184
for s , format , dt in data :
185
185
assert to_datetime (s , format = format , cache = cache ) == dt
186
186
187
- @pytest .mark .parametrize ("box,const" , [
188
- [True , pd .Index ],
189
- [False , np .array ]])
190
187
@pytest .mark .parametrize ("fmt,dates,expected_dates" , [
191
188
['%Y-%m-%d %H:%M:%S %Z' ,
192
189
['2010-01-01 12:00:00 UTC' ] * 2 ,
@@ -218,15 +215,15 @@ def test_to_datetime_format_weeks(self, cache):
218
215
tzinfo = pytz .FixedOffset (0 )), # pytz coerces to UTC
219
216
pd .Timestamp ('2010-01-01 12:00:00' ,
220
217
tzinfo = pytz .FixedOffset (0 ))]]])
221
- def test_to_datetime_parse_tzname_or_tzoffset (self , box , const ,
222
- fmt , dates , expected_dates ):
218
+ def test_to_datetime_parse_tzname_or_tzoffset (self , fmt , dates ,
219
+ expected_dates ):
223
220
# GH 13486
224
- result = pd .to_datetime (dates , format = fmt , box = box )
225
- expected = const (expected_dates )
221
+ result = pd .to_datetime (dates , format = fmt )
222
+ expected = pd . Index (expected_dates )
226
223
tm .assert_equal (result , expected )
227
224
228
225
with pytest .raises (ValueError ):
229
- pd .to_datetime (dates , format = fmt , box = box , utc = True )
226
+ pd .to_datetime (dates , format = fmt , utc = True )
230
227
231
228
@pytest .mark .parametrize ('offset' , [
232
229
'+0' , '-1foo' , 'UTCbar' , ':10' , '+01:000:01' , '' ])
@@ -256,7 +253,7 @@ def test_to_datetime_dtarr(self, tz):
256
253
result = to_datetime (arr )
257
254
assert result is arr
258
255
259
- result = to_datetime (arr , box = True )
256
+ result = to_datetime (arr )
260
257
assert result is arr
261
258
262
259
def test_to_datetime_pydatetime (self ):
@@ -363,9 +360,9 @@ def test_to_datetime_array_of_dt64s(self, cache):
363
360
364
361
# Assuming all datetimes are in bounds, to_datetime() returns
365
362
# an array that is equal to Timestamp() parsing
366
- tm .assert_numpy_array_equal (
367
- pd .to_datetime (dts , box = False , cache = cache ),
368
- np . array ([Timestamp (x ).asm8 for x in dts ])
363
+ tm .assert_index_equal (
364
+ pd .to_datetime (dts , cache = cache ),
365
+ pd . DatetimeIndex ([Timestamp (x ).asm8 for x in dts ])
369
366
)
370
367
371
368
# A list of datetimes where the last one is out of bounds
@@ -375,28 +372,26 @@ def test_to_datetime_array_of_dt64s(self, cache):
375
372
with pytest .raises (OutOfBoundsDatetime , match = msg ):
376
373
pd .to_datetime (dts_with_oob , errors = 'raise' )
377
374
378
- tm .assert_numpy_array_equal (
379
- pd .to_datetime (dts_with_oob , box = False , errors = 'coerce' ,
375
+ tm .assert_index_equal (
376
+ pd .to_datetime (dts_with_oob , errors = 'coerce' ,
380
377
cache = cache ),
381
- np . array (
378
+ pd . DatetimeIndex (
382
379
[
383
380
Timestamp (dts_with_oob [0 ]).asm8 ,
384
381
Timestamp (dts_with_oob [1 ]).asm8 ,
385
- tslib .iNaT ,
386
- ],
387
- dtype = 'M8'
382
+ pd .NaT
383
+ ]
388
384
)
389
385
)
390
386
391
387
# With errors='ignore', out of bounds datetime64s
392
388
# are converted to their .item(), which depending on the version of
393
389
# numpy is either a python datetime.datetime or datetime.date
394
- tm .assert_numpy_array_equal (
395
- pd .to_datetime (dts_with_oob , box = False , errors = 'ignore' ,
390
+ tm .assert_index_equal (
391
+ pd .to_datetime (dts_with_oob , errors = 'ignore' ,
396
392
cache = cache ),
397
- np .array (
398
- [dt .item () for dt in dts_with_oob ],
399
- dtype = 'O'
393
+ pd .Index (
394
+ [dt .item () for dt in dts_with_oob ]
400
395
)
401
396
)
402
397
@@ -622,20 +617,16 @@ def test_datetime_invalid_index(self, values, format, infer):
622
617
623
618
@pytest .mark .parametrize ("utc" , [True , None ])
624
619
@pytest .mark .parametrize ("format" , ['%Y%m%d %H:%M:%S' , None ])
625
- @pytest .mark .parametrize ("box" , [True , False ])
626
620
@pytest .mark .parametrize ("constructor" , [list , tuple , np .array , pd .Index ])
627
- def test_to_datetime_cache (self , utc , format , box , constructor ):
621
+ def test_to_datetime_cache (self , utc , format , constructor ):
628
622
date = '20130101 00:00:00'
629
623
test_dates = [date ] * 10 ** 5
630
624
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 )
635
- if box :
636
- tm .assert_index_equal (result , expected )
637
- else :
638
- tm .assert_numpy_array_equal (result , expected )
625
+
626
+ result = pd .to_datetime (data , utc = utc , format = format , cache = True )
627
+ expected = pd .to_datetime (data , utc = utc , format = format , cache = False )
628
+
629
+ tm .assert_index_equal (result , expected )
639
630
640
631
@pytest .mark .parametrize ("utc" , [True , None ])
641
632
@pytest .mark .parametrize ("format" , ['%Y%m%d %H:%M:%S' , None ])
@@ -684,7 +675,10 @@ def test_iso_8601_strings_with_same_offset(self):
684
675
def test_iso_8601_strings_same_offset_no_box (self ):
685
676
# GH 22446
686
677
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 )
678
+
679
+ with tm .assert_produces_warning (FutureWarning ):
680
+ result = pd .to_datetime (data , box = False )
681
+
688
682
expected = np .array ([
689
683
datetime (2018 , 1 , 4 , 9 , 1 , tzinfo = pytz .FixedOffset (540 )),
690
684
datetime (2018 , 1 , 4 , 9 , 2 , tzinfo = pytz .FixedOffset (540 ))
@@ -753,6 +747,16 @@ def test_timestamp_utc_true(self, ts, expected):
753
747
result = to_datetime (ts , utc = True )
754
748
assert result == expected
755
749
750
+ def test_to_datetime_box_deprecated (self ):
751
+ expected = np .datetime64 ('2018-09-09' )
752
+
753
+ # Deprecated - see GH24416
754
+ with tm .assert_produces_warning (FutureWarning ):
755
+ pd .to_datetime (expected , box = False )
756
+
757
+ result = pd .to_datetime (expected ).to_datetime64 ()
758
+ assert result == expected
759
+
756
760
757
761
class TestToDatetimeUnit (object ):
758
762
@pytest .mark .parametrize ('cache' , [True , False ])
@@ -891,7 +895,7 @@ def test_unit_rounding(self, cache):
891
895
def test_unit_ignore_keeps_name (self , cache ):
892
896
# GH 21697
893
897
expected = pd .Index ([15e9 ] * 2 , name = 'name' )
894
- result = pd .to_datetime (expected , errors = 'ignore' , box = True , unit = 's' ,
898
+ result = pd .to_datetime (expected , errors = 'ignore' , unit = 's' ,
895
899
cache = cache )
896
900
tm .assert_index_equal (result , expected )
897
901
@@ -1052,7 +1056,10 @@ def test_dataframe_box_false(self):
1052
1056
df = pd .DataFrame ({'year' : [2015 , 2016 ],
1053
1057
'month' : [2 , 3 ],
1054
1058
'day' : [4 , 5 ]})
1055
- result = pd .to_datetime (df , box = False )
1059
+
1060
+ with tm .assert_produces_warning (FutureWarning ):
1061
+ result = pd .to_datetime (df , box = False )
1062
+
1056
1063
expected = np .array (['2015-02-04' , '2016-03-05' ],
1057
1064
dtype = 'datetime64[ns]' )
1058
1065
tm .assert_numpy_array_equal (result , expected )
@@ -1069,8 +1076,7 @@ def test_dataframe_utc_true(self):
1069
1076
1070
1077
def test_to_datetime_errors_ignore_utc_true (self ):
1071
1078
# GH 23758
1072
- result = pd .to_datetime ([1 ], unit = 's' , box = True , utc = True ,
1073
- errors = 'ignore' )
1079
+ result = pd .to_datetime ([1 ], unit = 's' , utc = True , errors = 'ignore' )
1074
1080
expected = DatetimeIndex (['1970-01-01 00:00:01' ], tz = 'UTC' )
1075
1081
tm .assert_index_equal (result , expected )
1076
1082
@@ -1188,19 +1194,16 @@ def test_to_datetime_types(self, cache):
1188
1194
# assert result == expected
1189
1195
1190
1196
@pytest .mark .parametrize ('cache' , [True , False ])
1191
- @pytest .mark .parametrize ('box, klass' , [
1192
- [True , Index ],
1193
- [False , np .array ]
1194
- ])
1195
- def test_to_datetime_unprocessable_input (self , cache , box , klass ):
1197
+ def test_to_datetime_unprocessable_input (self , cache ):
1196
1198
# GH 4928
1197
1199
# GH 21864
1198
- result = to_datetime ([1 , '1' ], errors = 'ignore' , cache = cache , box = box )
1199
- expected = klass (np .array ([1 , '1' ], dtype = 'O' ))
1200
+ result = to_datetime ([1 , '1' ], errors = 'ignore' , cache = cache )
1201
+
1202
+ expected = Index (np .array ([1 , '1' ], dtype = 'O' ))
1200
1203
tm .assert_equal (result , expected )
1201
1204
msg = "invalid string coercion to datetime"
1202
1205
with pytest .raises (TypeError , match = msg ):
1203
- to_datetime ([1 , '1' ], errors = 'raise' , cache = cache , box = box )
1206
+ to_datetime ([1 , '1' ], errors = 'raise' , cache = cache )
1204
1207
1205
1208
def test_to_datetime_other_datetime64_units (self ):
1206
1209
# 5/25/2012
0 commit comments