1212from pandas ._libs .tslibs .strptime import array_strptime
1313from pandas .util ._decorators import deprecate_kwarg
1414
15+ from pandas .core .algorithms import unique
1516from pandas .core .dtypes .common import (
1617 ensure_object , is_datetime64_dtype , is_datetime64_ns_dtype ,
1718 is_datetime64tz_dtype , is_float , is_integer , is_integer_dtype ,
@@ -42,7 +43,7 @@ def _guess_datetime_format_for_array(arr, **kwargs):
4243 return _guess_datetime_format (arr [non_nan_elements [0 ]], ** kwargs )
4344
4445
45- def do_cache (arg , check_count : int , unique_share : float ):
46+ def should_cache (arg , check_count : int , unique_share : float ):
4647 """
4748 Decides whether to do caching.
4849
@@ -51,20 +52,25 @@ def do_cache(arg, check_count: int, unique_share: float):
5152
5253 Parameters
5354 ----------
54- arg: list , tuple, 1-d array, Series
55+ arg: listlike , tuple, 1-d array, Series
5556 check_count: int
57+ 0 < check_count <= len(arg)
5658 unique_share: float
59+ 0 < unique_share < 1
5760
5861 Returns
5962 -------
60- : bool
63+ do_caching : bool
6164 """
62- from pandas .core .algorithms import unique
65+ assert 0 < check_count <= len (arg )
66+ assert 0 < unique_share < 1
6367
64- unique = unique (arg [:check_count ])
65- if len (unique ) > check_count * unique_share :
66- return False
67- return True
68+ do_caching = True
69+
70+ unique_elements = unique (arg [:check_count ])
71+ if len (unique_elements ) > check_count * unique_share :
72+ do_caching = False
73+ return do_caching
6874
6975
7076def _maybe_cache (arg , format , cache , convert_listlike ):
@@ -73,7 +79,7 @@ def _maybe_cache(arg, format, cache, convert_listlike):
7379
7480 Parameters
7581 ----------
76- arg : integer, float, string, datetime, list , tuple, 1-d array, Series
82+ arg : listlike , tuple, 1-d array, Series
7783 format : string
7884 Strftime format to parse time
7985 cache : boolean
@@ -92,7 +98,7 @@ def _maybe_cache(arg, format, cache, convert_listlike):
9298 # Perform a quicker unique check
9399 from pandas import Index
94100
95- if not do_cache (arg , int (len (arg ) * 0.1 ), 0.7 ):
101+ if not should_cache (arg , int (len (arg ) * 0.1 ), 0.7 ):
96102 return cache_array
97103
98104 unique_dates = Index (arg ).unique ()
0 commit comments