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
16
15
from pandas .core .dtypes .common import (
17
16
ensure_object , is_datetime64_dtype , is_datetime64_ns_dtype ,
18
17
is_datetime64tz_dtype , is_float , is_integer , is_integer_dtype ,
23
22
24
23
from pandas ._typing import ArrayLike
25
24
from pandas .core import algorithms
25
+ from pandas .core .algorithms import unique
26
+
27
+ # ---------------------------------------------------------------------
28
+ # types used in annotations
29
+
30
+ ArrayConvertible = Union [list , tuple , ArrayLike , ABCSeries ]
31
+
32
+ # ---------------------------------------------------------------------
26
33
27
34
# ---------------------------------------------------------------------
28
35
# types used in annotations
@@ -43,7 +50,8 @@ def _guess_datetime_format_for_array(arr, **kwargs):
43
50
return _guess_datetime_format (arr [non_nan_elements [0 ]], ** kwargs )
44
51
45
52
46
- def should_cache (arg , unique_share = 0.7 , check_count = None ):
53
+ def should_cache (arg : ArrayConvertible , unique_share : float = 0.7 ,
54
+ check_count : Optional [int ] = None ) -> bool :
47
55
"""
48
56
Decides whether to do caching.
49
57
@@ -53,14 +61,22 @@ def should_cache(arg, unique_share=0.7, check_count=None):
53
61
Parameters
54
62
----------
55
63
arg: listlike, tuple, 1-d array, Series
56
- unique_share: float or None
64
+ unique_share: float, default=0.7, optional
57
65
0 < unique_share < 1
58
- check_count: int or None
66
+ check_count: int, optional
59
67
0 <= check_count <= len(arg)
60
68
61
69
Returns
62
70
-------
63
71
do_caching: bool
72
+
73
+ Notes
74
+ -----
75
+ By default for a sequence of less than 50 items in size, we don't do
76
+ caching; for the number of elements less than 5000, we take ten percent of
77
+ all elements to check for a uniqueness share; if the sequence size is more
78
+ than 5000, then we check only the first 500 elements.
79
+ All constants were chosen empirically by.
64
80
"""
65
81
do_caching = True
66
82
0 commit comments