@@ -186,7 +186,8 @@ def _guess_datetime_format_for_array(arr, **kwargs):
186186
187187def to_datetime (arg , errors = 'raise' , dayfirst = False , yearfirst = False ,
188188 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 ):
190191 """
191192 Convert argument to datetime.
192193
@@ -259,7 +260,11 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
259260 origin.
260261
261262 .. 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.
262266
267+ .. versionadded: 0.20.2
263268 Returns
264269 -------
265270 ret : datetime if parsing succeeded.
@@ -349,6 +354,16 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
349354
350355 def _convert_listlike (arg , box , format , name = None , tz = tz ):
351356
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 )
352367 if isinstance (arg , (list , tuple )):
353368 arg = np .array (arg , dtype = 'O' )
354369
0 commit comments