12
12
from pandas ._libs .tslibs .strptime import array_strptime
13
13
from pandas .util ._decorators import deprecate_kwarg
14
14
15
+ from pandas .core .algorithms import unique
15
16
from pandas .core .dtypes .common import (
16
17
ensure_object , is_datetime64_dtype , is_datetime64_ns_dtype ,
17
18
is_datetime64tz_dtype , is_float , is_integer , is_integer_dtype ,
@@ -42,7 +43,7 @@ def _guess_datetime_format_for_array(arr, **kwargs):
42
43
return _guess_datetime_format (arr [non_nan_elements [0 ]], ** kwargs )
43
44
44
45
45
- def do_cache (arg , check_count : int , unique_share : float ):
46
+ def should_cache (arg , check_count : int , unique_share : float ):
46
47
"""
47
48
Decides whether to do caching.
48
49
@@ -51,20 +52,25 @@ def do_cache(arg, check_count: int, unique_share: float):
51
52
52
53
Parameters
53
54
----------
54
- arg: list , tuple, 1-d array, Series
55
+ arg: listlike , tuple, 1-d array, Series
55
56
check_count: int
57
+ 0 < check_count <= len(arg)
56
58
unique_share: float
59
+ 0 < unique_share < 1
57
60
58
61
Returns
59
62
-------
60
- : bool
63
+ do_caching : bool
61
64
"""
62
- from pandas .core .algorithms import unique
65
+ assert 0 < check_count <= len (arg )
66
+ assert 0 < unique_share < 1
63
67
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
68
74
69
75
70
76
def _maybe_cache (arg , format , cache , convert_listlike ):
@@ -73,7 +79,7 @@ def _maybe_cache(arg, format, cache, convert_listlike):
73
79
74
80
Parameters
75
81
----------
76
- arg : integer, float, string, datetime, list , tuple, 1-d array, Series
82
+ arg : listlike , tuple, 1-d array, Series
77
83
format : string
78
84
Strftime format to parse time
79
85
cache : boolean
@@ -92,7 +98,7 @@ def _maybe_cache(arg, format, cache, convert_listlike):
92
98
# Perform a quicker unique check
93
99
from pandas import Index
94
100
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 ):
96
102
return cache_array
97
103
98
104
unique_dates = Index (arg ).unique ()
0 commit comments