Skip to content

Add error message for tz_localize #32979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
-

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you undo this removed line?

.. ---------------------------------------------------------------------------

Increased minimum versions for dependencies
Expand Down Expand Up @@ -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
^^^^^^^^^
Expand Down
8 changes: 6 additions & 2 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we wanted to give a sense of what the implementation bound was? e.g. f'Timestamp cannot be converted past {Timestamp.max}'

)


# ----------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/scalar/timestamp/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down