From 825e34fa6ed79c1d7693fb798f182739f38addd7 Mon Sep 17 00:00:00 2001 From: mcortesdf Date: Wed, 11 Sep 2019 14:35:27 +0100 Subject: [PATCH 1/3] add test for #9107 test to ensure OutOfBoundsDatetime exception is raised when calling pd.to_datetime with out-of-bounds date strings --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/tests/indexes/datetimes/test_tools.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 9840e4e94d28c..902503473c952 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -118,7 +118,7 @@ Datetimelike - Bug in :meth:`pandas.core.groupby.SeriesGroupBy.nunique` where ``NaT`` values were interfering with the count of unique values (:issue:`27951`) - Bug in :class:`Timestamp` subtraction when subtracting a :class:`Timestamp` from a ``np.datetime64`` object incorrectly raising ``TypeError`` (:issue:`28286`) - Addition and subtraction of integer or integer-dtype arrays with :class:`Timestamp` will now raise ``NullFrequencyError`` instead of ``ValueError`` (:issue:`28268`) -- +- New test to ensure OutOfBoundsDatetime exception is raised when calling :func:``pd.to_datetime`` with out-of-bounds date strings Timedelta diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index 9af0f47f6dce9..a57b69971a458 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -1028,6 +1028,12 @@ def test_to_datetime_box_deprecated(self): result = pd.to_datetime(expected).to_datetime64() assert result == expected + @pytest.mark.parametrize("dt_str", ["00010101", "13000101", "30000101", "99990101"]) + def test_old_date_out_of_bounds_exception(self, dt_str): + # GH 9107 + with pytest.raises(OutOfBoundsDatetime): + pd.to_datetime(dt_str, format="%Y%m%d") + class TestToDatetimeUnit: @pytest.mark.parametrize("cache", [True, False]) From b1861fd826a2d2f745e500683d5897febd49e22a Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 12 Sep 2019 10:23:40 +0100 Subject: [PATCH 2/3] Remove superfluous entry into whatsnew/v1.0.0.rst New test is not user facing, does not need to be included in release notes --- doc/source/whatsnew/v1.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 902503473c952..f36f312b1299e 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -118,7 +118,6 @@ Datetimelike - Bug in :meth:`pandas.core.groupby.SeriesGroupBy.nunique` where ``NaT`` values were interfering with the count of unique values (:issue:`27951`) - Bug in :class:`Timestamp` subtraction when subtracting a :class:`Timestamp` from a ``np.datetime64`` object incorrectly raising ``TypeError`` (:issue:`28286`) - Addition and subtraction of integer or integer-dtype arrays with :class:`Timestamp` will now raise ``NullFrequencyError`` instead of ``ValueError`` (:issue:`28268`) -- New test to ensure OutOfBoundsDatetime exception is raised when calling :func:``pd.to_datetime`` with out-of-bounds date strings Timedelta From 1b099d666f66ea6b0f36c42822c3b7a536215949 Mon Sep 17 00:00:00 2001 From: mcortesdf Date: Thu, 12 Sep 2019 10:25:56 +0100 Subject: [PATCH 3/3] Rename test to suggested, more informative name test_old_date_out_of_bounds_exception -> test_to_datetime_with_format_out_of_bounds --- pandas/tests/indexes/datetimes/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index a57b69971a458..9f0cc2555c246 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -1029,7 +1029,7 @@ def test_to_datetime_box_deprecated(self): assert result == expected @pytest.mark.parametrize("dt_str", ["00010101", "13000101", "30000101", "99990101"]) - def test_old_date_out_of_bounds_exception(self, dt_str): + def test_to_datetime_with_format_out_of_bounds(self, dt_str): # GH 9107 with pytest.raises(OutOfBoundsDatetime): pd.to_datetime(dt_str, format="%Y%m%d")