Skip to content

Commit abef2d5

Browse files
author
Sumanau Sareen
committed
Add error message for tz_localize
1 parent df49f53 commit abef2d5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pandas/_libs/tslibs/conversion.pyx

+6-2
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,14 @@ cdef inline check_overflows(_TSObject obj):
502502
# GH#12677
503503
if obj.dts.year == 1677:
504504
if not (obj.value < 0):
505-
raise OutOfBoundsDatetime
505+
raise OutOfBoundsDatetime(
506+
f'Timestamp cannot be converted within implementation bounds'
507+
)
506508
elif obj.dts.year == 2262:
507509
if not (obj.value > 0):
508-
raise OutOfBoundsDatetime
510+
raise OutOfBoundsDatetime(
511+
f'Timestamp cannot be converted within implementation bounds'
512+
)
509513

510514

511515
# ----------------------------------------------------------------------

pandas/tests/scalar/timestamp/test_timezones.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ def test_tz_localize_pushes_out_of_bounds(self):
2424
# GH#12677
2525
# tz_localize that pushes away from the boundary is OK
2626
pac = Timestamp.min.tz_localize("US/Pacific")
27+
msg = "Timestamp cannot be converted within implementation bounds"
2728
assert pac.value > Timestamp.min.value
2829
pac.tz_convert("Asia/Tokyo") # tz_convert doesn't change value
29-
with pytest.raises(OutOfBoundsDatetime):
30+
with pytest.raises(OutOfBoundsDatetime, match=msg):
3031
Timestamp.min.tz_localize("Asia/Tokyo")
3132

3233
# tz_localize that pushes away from the boundary is OK
3334
tokyo = Timestamp.max.tz_localize("Asia/Tokyo")
3435
assert tokyo.value < Timestamp.max.value
3536
tokyo.tz_convert("US/Pacific") # tz_convert doesn't change value
36-
with pytest.raises(OutOfBoundsDatetime):
37+
with pytest.raises(OutOfBoundsDatetime, match=msg):
3738
Timestamp.max.tz_localize("US/Pacific")
3839

3940
def test_tz_localize_ambiguous_bool(self):

0 commit comments

Comments
 (0)