-
Notifications
You must be signed in to change notification settings - Fork 408
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
Timezone Aware Datetime with Python>=3.12 #3298
Comments
So the whole situation is kind of a mess. Pandas apparent does actually support timezones but that gets stored under its own Dtype; numpy I'm not even sure how you could open a netCDF file and make the time axis set the timezone to UTC, but it seems to be possible? Given that, for MetPy I'm coming around to the idea that while we should address the warnings and avoid deprecated methods (#3255), we should keep using tz-naive datetime.utcnow() becomes datetime.now(timezone.utc).replace(tzinfo=None) That feels ugly to drop timezone information (which really is nice to have for robust labelling, etc.), but would preserve the existing behavior and avoid a bunch of headaches for our users until the rest of the ecosystem is more ready to deal with them. |
So for completeness, #3255 implements this using a sensible mix:
Is there anything more we need to do in MetPy itself about this? |
What went wrong?
In Python 3.12 the
datetime.utcnow()
functionality is removed. The solution is to move to timezone aware datetime objects withThe issue that comes up is that our data that we bring in, whether surface, upper air, or gridded have traditionally not been timezone aware. There are many instances of setting a datetime, whether with
utcnow()
or with a manual setting (e.g.,datetime(2017, 3, 8, 12)
that are/were timezone naive. The issue comes in when comparing timezone aware to timezone naive values as that comparison cannot be done. This is most likely to come up when subsetting data for a certain time or time window.This issue captures our need to address this with the challenge being in determining how to address this change holistically. Some changes may need to be in MetPy, while others lie upstream with other packages or might require code examples to highlight how to get the proper object type for users.
Operating System
MacOS
Version
1.5.1
Python Version
3.12
Code to Reproduce
Errors, Traceback, and Logs
The text was updated successfully, but these errors were encountered: