-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add date overflow message to tz_localize (#32967) #35187
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -605,13 +605,20 @@ cdef inline check_overflows(_TSObject obj): | |
OutOfBoundsDatetime | ||
""" | ||
# GH#12677 | ||
fmt = (f'{obj.dts.year}-{obj.dts.month:02d}-{obj.dts.day:02d} ' | ||
f'{obj.dts.hour:02d}:{obj.dts.min:02d}:{obj.dts.sec:02d}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you delay evaluating this until we know we're raising? also pls use double-quotes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can milk a tiny bit more performance by avoiding defining the lambda There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, you end up having to actually either define everything twice (gross) or use a function call, which is precisely what i am suggesting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Even if you're not evaluating the lambda, defining it at runtime is overhead we can avoid. i expect the performance difference is tiny, but fstrings showed up in a perf regression @TomAugspurger fixed the other day. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just went the defining twice route for now, but I agree it kinda feels gross. Let me know if I should change it. |
||
if obj.dts.year == 1677: | ||
if not (obj.value < 0): | ||
raise OutOfBoundsDatetime | ||
from pandas._libs.tslibs.timestamps import Timestamp | ||
raise OutOfBoundsDatetime( | ||
f'Converting {fmt} underflows past {Timestamp.min}' | ||
) | ||
elif obj.dts.year == 2262: | ||
if not (obj.value > 0): | ||
raise OutOfBoundsDatetime | ||
|
||
from pandas._libs.tslibs.timestamps import Timestamp | ||
raise OutOfBoundsDatetime( | ||
f'Converting {fmt} overflows past {Timestamp.max}' | ||
) | ||
|
||
# ---------------------------------------------------------------------- | ||
# Localization | ||
|
Uh oh!
There was an error while loading. Please reload this page.