Skip to content

Commit 9c1ab11

Browse files
committed
Test that to_datetime produces equal result for cache on and off
1 parent 89c8741 commit 9c1ab11

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/indexes/datetimes/test_tools.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
from pandas.util import testing as tm
3030
from pandas.util.testing import assert_series_equal
3131

32+
from hypothesis.extra.pytz import timezones
33+
from hypothesis.strategies import datetimes
34+
from hypothesis import given
35+
3236

3337
class TestTimeConversionFormats:
3438

@@ -480,6 +484,29 @@ def test_to_datetime_offset(self, cache):
480484
result = pd.to_datetime(arr, cache=cache)
481485
tm.assert_index_equal(result, expected)
482486

487+
@pytest.mark.parametrize('errors', ('ignore', 'coerce', 'raise'))
488+
@pytest.mark.parametrize('suffix', ([], ['foo']))
489+
@pytest.mark.parametrize('convertor', (lambda x: x, str))
490+
@given(date1=datetimes(timezones=timezones()),
491+
date2=datetimes(timezones=timezones()))
492+
def test_to_datetime_cache_errors(self, date1, date2, suffix,
493+
errors, convertor):
494+
arg = [convertor(date1), convertor(date2)] * 5 + suffix
495+
496+
def _get_answer(cache):
497+
try:
498+
return pd.to_datetime(arg, cache=cache, errors=errors)
499+
except ValueError as err:
500+
return err.args
501+
502+
cache_on = _get_answer(cache=True)
503+
cache_off = _get_answer(cache=False)
504+
assert type(cache_on) == type(cache_off)
505+
if isinstance(cache_on, pd.Index):
506+
tm.assert_index_equal(cache_on, cache_off)
507+
else:
508+
assert cache_on == cache_off
509+
483510
@pytest.mark.parametrize('cache', [True, False])
484511
def test_to_datetime_tz_pytz(self, cache):
485512
# see gh-8260

0 commit comments

Comments
 (0)