From 8ebd1b6e11eb18927c845cdd9236d2c5f5190b11 Mon Sep 17 00:00:00 2001 From: Sumanau Sareen Date: Tue, 24 Mar 2020 20:43:09 +0530 Subject: [PATCH 1/2] Add error message for tz_localize --- pandas/_libs/tslibs/conversion.pyx | 8 ++++++-- pandas/tests/scalar/timestamp/test_timezones.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 5a8d0a0ec1670..e12ec4e8f9c6c 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -523,10 +523,14 @@ cdef inline check_overflows(_TSObject obj): # GH#12677 if obj.dts.year == 1677: if not (obj.value < 0): - raise OutOfBoundsDatetime + raise OutOfBoundsDatetime( + f'Timestamp cannot be converted within implementation bounds' + ) elif obj.dts.year == 2262: if not (obj.value > 0): - raise OutOfBoundsDatetime + raise OutOfBoundsDatetime( + f'Timestamp cannot be converted within implementation bounds' + ) # ---------------------------------------------------------------------- diff --git a/pandas/tests/scalar/timestamp/test_timezones.py b/pandas/tests/scalar/timestamp/test_timezones.py index 9611c827be6fe..bd49467695d00 100644 --- a/pandas/tests/scalar/timestamp/test_timezones.py +++ b/pandas/tests/scalar/timestamp/test_timezones.py @@ -25,6 +25,7 @@ def test_tz_localize_pushes_out_of_bounds(self): # GH#12677 # tz_localize that pushes away from the boundary is OK pac = Timestamp.min.tz_localize("US/Pacific") + msg = "Timestamp cannot be converted within implementation bounds" assert pac.value > Timestamp.min.value pac.tz_convert("Asia/Tokyo") # tz_convert doesn't change value with pytest.raises(OutOfBoundsDatetime, match=msg): From 6407d8d76b204896cfa4db75ec4700e6db5e5ef2 Mon Sep 17 00:00:00 2001 From: Sumanau Sareen Date: Sat, 28 Mar 2020 12:19:28 +0530 Subject: [PATCH 2/2] Added whats new entry --- doc/source/whatsnew/v1.1.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index cd1cb0b64f74a..31dc4b8dccb8c 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -101,7 +101,6 @@ Other enhancements - :meth:`~pandas.core.groupby.GroupBy.transform` has gained ``engine`` and ``engine_kwargs`` arguments that supports executing functions with ``Numba`` (:issue:`32854`) - :meth:`~pandas.core.resample.Resampler.interpolate` now supports SciPy interpolation method :class:`scipy.interpolate.CubicSpline` as method ``cubicspline`` (:issue:`33670`) - - .. --------------------------------------------------------------------------- Increased minimum versions for dependencies @@ -462,6 +461,8 @@ Datetimelike - Bug in :meth:`DatetimeIndex.to_period` not infering the frequency when called with no arguments (:issue:`33358`) - Bug in :meth:`DatetimeIndex.tz_localize` incorrectly retaining ``freq`` in some cases where the original freq is no longer valid (:issue:`30511`) - Bug in :meth:`DatetimeIndex.intersection` losing ``freq`` and timezone in some cases (:issue:`33604`) +- ``OutOfBoundsDatetime`` issues an error message when timestamp is out of implementation bounds. (:issue:`32967`) + Timedelta ^^^^^^^^^