Skip to content

Commit 7ed279a

Browse files
committed
added errors message; added tests
1 parent 4523494 commit 7ed279a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

pandas/core/tools/datetimes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def should_cache(arg, check_count: int, unique_share: float):
6262
-------
6363
do_caching: bool
6464
"""
65-
assert 0 < check_count <= len(arg)
66-
assert 0 < unique_share < 1
65+
assert 0 < check_count <= len(arg), ('check_count must be in next bounds: '
66+
'(0; len(arg)]')
67+
assert 0 < unique_share < 1, 'unique_share must be in next bounds: (0; 1)'
6768

6869
do_caching = True
6970

pandas/tests/indexes/datetimes/test_tools.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,3 +2032,23 @@ def test_arg_tz_ns_unit(self, offset, utc, exp):
20322032
result = to_datetime([arg], unit='ns', utc=utc)
20332033
expected = to_datetime([exp])
20342034
tm.assert_index_equal(result, expected)
2035+
2036+
2037+
@pytest.mark.parametrize('listlike,do_caching', [
2038+
([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], False),
2039+
([1, 1, 1, 1, 4, 5, 6, 7, 8, 9], True)
2040+
])
2041+
def test_should_cache(listlike, do_caching):
2042+
assert tools.should_cache(listlike, check_count=len(listlike),
2043+
unique_share=0.7) == do_caching
2044+
2045+
2046+
@pytest.mark.parametrize('check_count,unique_share, err_message', [
2047+
(11, 0.5, r'check_count must be in next bounds: \(0; len\(arg\)]'),
2048+
(10, 2, r'unique_share must be in next bounds: \(0; 1\)')
2049+
])
2050+
def test_should_cache_errors(check_count, unique_share, err_message):
2051+
arg = [5] * 10
2052+
2053+
with pytest.raises(AssertionError, match=err_message):
2054+
tools.should_cache(arg, check_count, unique_share)

0 commit comments

Comments
 (0)