@@ -186,7 +186,8 @@ def _guess_datetime_format_for_array(arr, **kwargs):
186
186
187
187
def to_datetime (arg , errors = 'raise' , dayfirst = False , yearfirst = False ,
188
188
utc = None , box = True , format = None , exact = True ,
189
- unit = None , infer_datetime_format = False , origin = 'unix' ):
189
+ unit = None , infer_datetime_format = False , origin = 'unix' ,
190
+ cache = True ):
190
191
"""
191
192
Convert argument to datetime.
192
193
@@ -259,7 +260,11 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
259
260
origin.
260
261
261
262
.. versionadded: 0.20.0
263
+ cache_datetime : boolean, default False
264
+ If True, use a cache of unique, converted dates to apply the datetime
265
+ conversion. Produces signficant speed-ups when parsing duplicate date.
262
266
267
+ .. versionadded: 0.20.2
263
268
Returns
264
269
-------
265
270
ret : datetime if parsing succeeded.
@@ -349,6 +354,16 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
349
354
350
355
def _convert_listlike (arg , box , format , name = None , tz = tz ):
351
356
357
+ datetime_cache = None
358
+ if cache and is_list_like (arg ) and not isinstance (arg , DatetimeIndex ):
359
+ unique_dates = algorithms .unique (arg )
360
+ if len (unique_dates ) != len (arg ):
361
+ datetime_cache = Series (pd .to_datetime (unique_dates ,
362
+ errors = errors , dayfirst = dayfirst ,
363
+ yearfirst = yearfirst , utc = utc , box = box , format = format ,
364
+ exact = exact , unit = unit ,
365
+ infer_datetime_format = infer_datetime_format ,
366
+ origin = origin , cache = False ), index = unique_dates )
352
367
if isinstance (arg , (list , tuple )):
353
368
arg = np .array (arg , dtype = 'O' )
354
369
0 commit comments