@@ -38,7 +38,8 @@ def _guess_datetime_format_for_array(arr, **kwargs):
3838
3939def to_datetime (arg , errors = 'raise' , dayfirst = False , yearfirst = False ,
4040 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 ):
4243 """
4344 Convert argument to datetime.
4445
@@ -111,7 +112,11 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
111112 origin.
112113
113114 .. 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.
114118
119+ .. versionadded: 0.20.2
115120 Returns
116121 -------
117122 ret : datetime if parsing succeeded.
@@ -201,6 +206,16 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
201206
202207 def _convert_listlike (arg , box , format , name = None , tz = tz ):
203208
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 )
204219 if isinstance (arg , (list , tuple )):
205220 arg = np .array (arg , dtype = 'O' )
206221
0 commit comments