|
3 | 3 | """
|
4 | 4 | import operator
|
5 | 5 |
|
| 6 | +from dateutil.parser._parser import ParserError |
6 | 7 | import numpy as np
|
7 | 8 | import pytest
|
8 | 9 |
|
9 | 10 | from pandas._libs.tslibs import tz_compare
|
10 | 11 | from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
|
| 12 | +from pandas.errors import OutOfBoundsDatetime |
11 | 13 |
|
12 | 14 | from pandas.core.dtypes.dtypes import DatetimeTZDtype
|
13 | 15 |
|
@@ -657,3 +659,22 @@ def test_coerce_fallback(self, error):
|
657 | 659 | assert result[1] is not pd.NaT
|
658 | 660 |
|
659 | 661 | tm.assert_series_equal(expected, result)
|
| 662 | + |
| 663 | + expected2 = pd.Series([pd.Timestamp("2000-01-01 00:00:00"), pd.NaT]) |
| 664 | + |
| 665 | + es1 = pd.Series(["1/1/2000", "7/12/1200"]) |
| 666 | + es2 = pd.Series(["1/1/2000", "Hello"]) |
| 667 | + |
| 668 | + if error == "coerce": |
| 669 | + eres1 = pd.to_datetime(es1, errors=error, infer_datetime_format=True) |
| 670 | + eres2 = pd.to_datetime(es2, errors=error, infer_datetime_format=True) |
| 671 | + tm.assert_series_equal(expected2, eres1) |
| 672 | + tm.assert_series_equal(expected2, eres2) |
| 673 | + else: |
| 674 | + with pytest.raises( |
| 675 | + OutOfBoundsDatetime, match="Out of bounds nanosecond timestamp" |
| 676 | + ): |
| 677 | + pd.to_datetime(es1, errors=error, infer_datetime_format=True) |
| 678 | + |
| 679 | + with pytest.raises(ParserError, match="Unknown string format: Hello"): |
| 680 | + pd.to_datetime(es2, errors=error, infer_datetime_format=True) |
0 commit comments