You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to handle datetime arrays with timezone information? #3656
Follow GMT (allow users to plot data at a non-UTC timezone, by ignoring the timezone offset) [breaking change]
Follow NumPy, whereby the data will from any non-UTC timezone will be converted to UTC always [current behaviour]
If going with 2, we should at least raise a warning if a non-UTC timezone is used, that a conversion is taking place. If going with 1, we would need to special-case datetime types, that might mean extra logic in the _to_numpy function, or having to keep array_to_datetime (so don't merge #3507 yet).
Context is that we need to decide on whether users would expect that datetime arrays/types (e.g. Python datetime.datetime, pandas.Series with pandas.Timestamp, pyarrow.timestamp, etc) that have non-UTC timezones should be plotted in the same non-UTC timezone, or have an automated conversion to a UTC timezone before plotting.
Vote 🚀 for option 1, and 👀 for option 2. Do comment down below to explain.
datetime arrays (e.g. pandas.Series with pandas.Timestamp, pyarrow.date32, pyarrow.date64, etc) that have non-UTC timezones
pyarrow.date32/pyarrow.date64 are timezone-unware. As far as I know, only datetime.datetime, datetime.time, pandas.DatetimeTZDtype and pyarrow.timestamp are timezone-aware.
I feel we should go with option 1, so the behavior is consistent with both GMT and the Python world (at least for matplotlib and pandas).
datetime arrays (e.g. pandas.Series with pandas.Timestamp, pyarrow.date32, pyarrow.date64, etc) that have non-UTC timezones
pyarrow.date32/pyarrow.date64 are timezone-unware. As far as I know, only datetime.datetime, datetime.time, pandas.DatetimeTZDtype and pyarrow.timestamp are timezone-aware.
Yep, was typing this out too quickly. Have updated the top-post to clarify this.
I feel we should go with option 1, so the behavior is consistent with both GMT and the Python world (at least for matplotlib and pandas).
I'm trying to get some historical context on how matplotlib/pandas has handled timezone plotting before. It seems like matplotlib used to have a plot_date() function which allows setting of a tz parameter, but this was deprecated in matplotlib/matplotlib#18154 and it's unclear/confusing on what the regular matplotlib .plot function does now in terms of timezone handling.
There's also an interesting case on what to do when plotting two or more arrays with different timezones (e.g. UTC and Europe/Berlin time) at matplotlib/matplotlib#8072 (comment). With option 2, everything is converted to UTC so things will be plotted 'correctly'; but with option 1, ignoring the timezones means the data would be plotted in a non-deterministic manner depending on which array (UTC or Europe/Berlin) was passed in first.
it's unclear/confusing on what the regular matplotlib .plot function does now in terms of timezone handling.
Isn't it clear that matplotlib's plot method is timezone-aware from my example above? The first point is plotted at 01-01 (Asia/Shanghai), not 12-31 (UTC).
with option 1, ignoring the timezones means the data would be plotted in a non-deterministic manner depending on which array (UTC or Europe/Berlin) was passed in first.
This won't be a case in GMT or PyGMT, since arrays can be processed independently. What makes more troubles is the handling of datetime with different timezones in arguments (although people are unlikely and unrecommended to use mixed timezones) like:
Activity
seisman commentedon Nov 28, 2024
pyarrow.date32/pyarrow.date64are timezone-unware. As far as I know, onlydatetime.datetime,datetime.time,pandas.DatetimeTZDtypeandpyarrow.timestampare timezone-aware.I feel we should go with option 1, so the behavior is consistent with both GMT and the Python world (at least for matplotlib and pandas).
weiji14 commentedon Nov 28, 2024
Yep, was typing this out too quickly. Have updated the top-post to clarify this.
I'm trying to get some historical context on how matplotlib/pandas has handled timezone plotting before. It seems like matplotlib used to have a
plot_date()function which allows setting of atzparameter, but this was deprecated in matplotlib/matplotlib#18154 and it's unclear/confusing on what the regular matplotlib.plotfunction does now in terms of timezone handling.There's also an interesting case on what to do when plotting two or more arrays with different timezones (e.g. UTC and Europe/Berlin time) at matplotlib/matplotlib#8072 (comment). With option 2, everything is converted to UTC so things will be plotted 'correctly'; but with option 1, ignoring the timezones means the data would be plotted in a non-deterministic manner depending on which array (UTC or Europe/Berlin) was passed in first.
seisman commentedon Nov 29, 2024
Isn't it clear that matplotlib's
plotmethod is timezone-aware from my example above? The first point is plotted at 01-01 (Asia/Shanghai), not 12-31 (UTC).This won't be a case in GMT or PyGMT, since arrays can be processed independently. What makes more troubles is the handling of datetime with different timezones in arguments (although people are unlikely and unrecommended to use mixed timezones) like: