Skip to content
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

Add date overflow message to tz_localize (#32967) #35187

Merged
merged 2 commits into from
Jul 16, 2020

Conversation

gabrielNT
Copy link
Contributor

@gabrielNT gabrielNT commented Jul 9, 2020

Added an error message to tz_localize when the timestamp overflows. I got a little confused by the history in #32979 as some changes were lost on the force pushes, but I tried to handle all review comments.

@@ -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}')
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

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

you can use a lambda x: ... here and use .format(obj)

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 can milk a tiny bit more performance by avoiding defining the lambda

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

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

define everything twice (gross) or use a function call

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -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}')
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use a lambda x: ... here and use .format(obj)

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Datetime Datetime data dtype labels Jul 9, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can u modify one of the tests that hits these to check that the error message matches (likely it just tests the type of the error message now)

@gabrielNT
Copy link
Contributor Author

can u modify one of the tests that hits these to check that the error message matches (likely it just tests the type of the error message now)

Hmmm, the only test I found that was actually raising this purposefully was test_tz_localize_pushes_out_of_bounds (already covered in this PR). Did I miss anything?

@gabrielNT gabrielNT requested a review from jreback July 15, 2020 22:55
@jreback jreback added this to the 1.1 milestone Jul 16, 2020
@jreback jreback merged commit f0d57d9 into pandas-dev:master Jul 16, 2020
@jreback
Copy link
Contributor

jreback commented Jul 16, 2020

thanks @gabrielNT

fangchenli pushed a commit to fangchenli/pandas that referenced this pull request Jul 16, 2020
…ev#35187)

* Add date overflow message to tz_localize (pandas-dev#32967)

* Delay evaluating timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty error message in tz_localize
3 participants