Skip to content

Commit c5d141c

Browse files
committed
fix bug when 'check_count' == 0
1 parent 7ed279a commit c5d141c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pandas/core/tools/datetimes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,21 @@ def should_cache(arg, check_count: int, unique_share: float):
5454
----------
5555
arg: listlike, tuple, 1-d array, Series
5656
check_count: int
57-
0 < check_count <= len(arg)
57+
0 <= check_count <= len(arg)
5858
unique_share: float
5959
0 < unique_share < 1
6060
6161
Returns
6262
-------
6363
do_caching: bool
6464
"""
65-
assert 0 < check_count <= len(arg), ('check_count must be in next bounds: '
66-
'(0; len(arg)]')
65+
assert 0 <= check_count <= len(arg), ('check_count must be in next bounds:'
66+
' [0; len(arg)]')
6767
assert 0 < unique_share < 1, 'unique_share must be in next bounds: (0; 1)'
6868

69+
if check_count == 0:
70+
return False
71+
6972
do_caching = True
7073

7174
unique_elements = unique(arg[:check_count])

pandas/tests/indexes/datetimes/test_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ def test_should_cache(listlike, do_caching):
20442044

20452045

20462046
@pytest.mark.parametrize('check_count,unique_share, err_message', [
2047-
(11, 0.5, r'check_count must be in next bounds: \(0; len\(arg\)]'),
2047+
(11, 0.5, r'check_count must be in next bounds: [0; len\(arg\)]'),
20482048
(10, 2, r'unique_share must be in next bounds: \(0; 1\)')
20492049
])
20502050
def test_should_cache_errors(check_count, unique_share, err_message):

0 commit comments

Comments
 (0)