-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Handle time normalization for nonexistent and ambiguous times #2133
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 10 commits
30bb319
6000bb2
6354443
2348afd
844a8b0
92b1d28
5b79e00
f271274
2466e7b
4ed2315
104bb23
5f85c32
441b3e9
406924e
1935952
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1360,6 +1360,11 @@ def hour_angle(times, longitude, equation_of_time): | |||||||||||||
| times : :class:`pandas.DatetimeIndex` | ||||||||||||||
| Corresponding timestamps, must be localized to the timezone for the | ||||||||||||||
| ``longitude``. | ||||||||||||||
|
|
||||||||||||||
| A `pytz.exceptions.AmbiguousTimeError` could be raised if any of the | ||||||||||||||
| given times are on a day where the local daylight savings transition happened | ||||||||||||||
| at midnight. If you're working with such a timezone, consider converting to | ||||||||||||||
| a non-DST timezone (i.e. GMT-4) before calling this function. | ||||||||||||||
| longitude : numeric | ||||||||||||||
| Longitude in degrees | ||||||||||||||
| equation_of_time : numeric | ||||||||||||||
|
|
@@ -1391,7 +1396,17 @@ def hour_angle(times, longitude, equation_of_time): | |||||||||||||
| times = times.tz_localize('utc') | ||||||||||||||
| tzs = np.array([ts.utcoffset().total_seconds() for ts in times]) / 3600 | ||||||||||||||
|
|
||||||||||||||
| hrs_minus_tzs = (times - times.normalize()) / pd.Timedelta('1h') - tzs | ||||||||||||||
| # Some timezones have a DST shift at midnight: | ||||||||||||||
| # 11:59pm -> 1:00am - results in a nonexistent midnight | ||||||||||||||
| # 12:59am -> 12:00am - results in an ambiguous midnight | ||||||||||||||
| # We remove the timezone before normalizing for this reason. | ||||||||||||||
| naive_normalized_times = times.tz_localize(None).normalize() | ||||||||||||||
|
|
||||||||||||||
| # Use Pandas functionality for shifting nonexistent times forward | ||||||||||||||
| normalized_times = naive_normalized_times.tz_localize( | ||||||||||||||
| times.tz, nonexistent='shift_forward', ambiguous='raise') | ||||||||||||||
|
||||||||||||||
| # Use Pandas functionality for shifting nonexistent times forward | |
| normalized_times = naive_normalized_times.tz_localize( | |
| times.tz, nonexistent='shift_forward', ambiguous='raise') | |
| # Use Pandas functionality for shifting nonexistent times forward | |
| normalized_times = naive_normalized_times.tz_localize( | |
| times.tz, nonexistent=nonexistent, ambiguous=ambiguous) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scttnlsn could you comment on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user would not necessarily be blocked if the exception is raised. They'd just need to convert the given times to a non-DST timezone ahead of calling hour_angle. The documentation is updated to mention this.
infer won't really work as mentioned here: #2133 (comment) The other options are to raise (current approach) or to have NaNs returned where the times are ambiguous (the user still likely needs to deal with that case).
I'm personally of the opinion that forcing the user to convert to a non-DST timezone is a fine approach but I could understand someone might want to have NaNs instead.
Uh oh!
There was an error while loading. Please reload this page.