@@ -38,7 +38,8 @@ def _guess_datetime_format_for_array(arr, **kwargs):
38
38
39
39
def to_datetime (arg , errors = 'raise' , dayfirst = False , yearfirst = False ,
40
40
utc = None , box = True , format = None , exact = True ,
41
- unit = None , infer_datetime_format = False , origin = 'unix' ):
41
+ unit = None , infer_datetime_format = False , origin = 'unix' ,
42
+ cache = True ):
42
43
"""
43
44
Convert argument to datetime.
44
45
@@ -111,7 +112,11 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
111
112
origin.
112
113
113
114
.. versionadded: 0.20.0
115
+ cache_datetime : boolean, default False
116
+ If True, use a cache of unique, converted dates to apply the datetime
117
+ conversion. Produces signficant speed-ups when parsing duplicate date.
114
118
119
+ .. versionadded: 0.20.2
115
120
Returns
116
121
-------
117
122
ret : datetime if parsing succeeded.
@@ -201,6 +206,16 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
201
206
202
207
def _convert_listlike (arg , box , format , name = None , tz = tz ):
203
208
209
+ datetime_cache = None
210
+ if cache and is_list_like (arg ) and not isinstance (arg , DatetimeIndex ):
211
+ unique_dates = algorithms .unique (arg )
212
+ if len (unique_dates ) != len (arg ):
213
+ datetime_cache = Series (pd .to_datetime (unique_dates ,
214
+ errors = errors , dayfirst = dayfirst ,
215
+ yearfirst = yearfirst , utc = utc , box = box , format = format ,
216
+ exact = exact , unit = unit ,
217
+ infer_datetime_format = infer_datetime_format ,
218
+ origin = origin , cache = False ), index = unique_dates )
204
219
if isinstance (arg , (list , tuple )):
205
220
arg = np .array (arg , dtype = 'O' )
206
221
0 commit comments