-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Allow timedelta to be converted to a ordinalf #8730
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 all commits
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 |
---|---|---|
|
@@ -207,16 +207,19 @@ def _get_rc_timezone(): | |
|
||
def _to_ordinalf(dt): | ||
""" | ||
Convert :mod:`datetime`or :mod:`date` to the Gregorian date as UTC float | ||
days, preserving hours, minutes, seconds and microseconds. Return value | ||
is a :func:`float`. | ||
Convert :mod:`datetime`, :mod:`date` or :mod:`timedelta` to the Gregorian | ||
date as UTC float days, preserving hours, minutes, seconds and | ||
microseconds. Return value is a :func:`float`. | ||
""" | ||
# Convert to UTC | ||
tzi = getattr(dt, 'tzinfo', None) | ||
if tzi is not None: | ||
dt = dt.astimezone(UTC) | ||
tzi = UTC | ||
|
||
if isinstance(dt, datetime.timedelta): | ||
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. This seems like the wrong place to decide whether or not this is 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. how else would you compute widths? It is a similar problem to temperatures. You can't simply convert a 5 degrees C temperature change into Fahrenheit temperature change (a big annoyance of mine when reading news articles that blindly injects unit conversions) 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. @WeatherGod I expressed my reservations a bit more in this comment. One problem with this as a solution to #4916 is that a corollary to #4916 is that (if I understand correctly) I don't know enough about the way the width processing and unit framework to know what the right seam is, but I would think that the right place to do the type check would be earlier in the pipeline, when you still know whether this is supposed to be units of 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. Another thing to note about this solution is that ideally the way this would work is that Consider that if the plot's width is calculated by adding 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. ooh, now that is an attractive option. |
||
return dt.total_seconds() / SEC_PER_DAY | ||
|
||
base = float(dt.toordinal()) | ||
|
||
# If it's sufficiently datetime-like, it will have a `date()` method | ||
|