@@ -49,15 +49,17 @@ def _maybe_cache(arg, format, cache, tz, _convert_listlike):
49
49
cache_array = Series (cache_dates , index = unique_dates )
50
50
return cache_array
51
51
52
- def _convert_and_box_cache (arg , cache_array , box , name = None ):
52
+ def _convert_and_box_cache (arg , cache_array , box , errors , tz , name = None ):
53
53
"""Convert array of dates with a cache and box the result"""
54
54
from pandas import Series
55
55
from pandas .core .indexes .datetimes import DatetimeIndex
56
56
result = Series (arg ).map (cache_array )
57
57
if box :
58
- result = DatetimeIndex (result , name = name )
59
- else :
60
- result = result .values
58
+ if errors == 'ignore' :
59
+ from pandas import Index
60
+ result = Index (result )
61
+ else :
62
+ result = DatetimeIndex (result , tz = tz , name = name )
61
63
return result
62
64
63
65
def to_datetime (arg , errors = 'raise' , dayfirst = False , yearfirst = False ,
@@ -410,14 +412,14 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
410
412
elif isinstance (arg , ABCIndexClass ):
411
413
cache_array = _maybe_cache (arg , format , cache , tz , _convert_listlike )
412
414
if not cache_array .empty :
413
- result = _convert_and_box_cache (arg , cache_array , box ,
415
+ result = _convert_and_box_cache (arg , cache_array , box , errors , tz ,
414
416
name = arg .name )
415
417
else :
416
418
result = _convert_listlike (arg , box , format , name = arg .name )
417
419
elif is_list_like (arg ):
418
420
cache_array = _maybe_cache (arg , format , cache , tz , _convert_listlike )
419
421
if not cache_array .empty :
420
- result = _convert_and_box_cache (arg , cache_array , box )
422
+ result = _convert_and_box_cache (arg , cache_array , box , errors , tz )
421
423
else :
422
424
result = _convert_listlike (arg , box , format )
423
425
else :
0 commit comments