|
29 | 29 | from pandas.util import testing as tm
|
30 | 30 | from pandas.util.testing import assert_series_equal
|
31 | 31 |
|
| 32 | +from hypothesis.extra.pytz import timezones |
| 33 | +from hypothesis.strategies import datetimes |
| 34 | +from hypothesis import given |
| 35 | + |
32 | 36 |
|
33 | 37 | class TestTimeConversionFormats:
|
34 | 38 |
|
@@ -480,6 +484,29 @@ def test_to_datetime_offset(self, cache):
|
480 | 484 | result = pd.to_datetime(arr, cache=cache)
|
481 | 485 | tm.assert_index_equal(result, expected)
|
482 | 486 |
|
| 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 | + |
483 | 510 | @pytest.mark.parametrize('cache', [True, False])
|
484 | 511 | def test_to_datetime_tz_pytz(self, cache):
|
485 | 512 | # see gh-8260
|
|
0 commit comments