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
Drop use of pytz dependency in next major release #10443
Comments
I am 👍 on this and dropping pytz as a run-time dependency, but we should keep a few tests using it. |
Do we even need to? Aren't tz implementations simply supposed to inherit https://docs.python.org/3/library/datetime.html#datetime.tzinfo and that should be the ground truth? |
@anntzer When I prepare the PR, I'll look into how much special-case code is necessary to support One thing I'll note is that basically anything that operates entirely on the "absolute timeline" should be no problem, because for both dt_utc = dt.astimezone(tz.tzutc())
dt_utc_txformed = txform(dt_utc)
dt_txformed = dt_utc_txformed.astimezone(dt.tzinfo) These aware-to-aware transformations are supported perfectly well by both |
Currently
matplotlib
defaults to usingpytz
for time zone support, I think that this should be dropped in favor of usingdateutil.tz
, which supports everythingpytz
does and more.Case for
dateutil
For starters,
dateutil
is already a dependency, so this removes rather than replaces a dependency. Additionally, the time zonesdateutil
provides properly implement thetzinfo
protocol, whilepytz
uses a non-standard API that is famously confusing.Additionally, as of
dateutil==2.6.0
,dateutil
has support for thefold
attribute introduced in PEP 495. It is currently recommended in the Python 3.6 documentation (scroll up a bit, that's the closest anchor) for this reason. It is unlikely thatpytz
will implementfold
support, as that's not really howpytz
works.I'll also say that most people seem to think that
pytz
already works likedateutil
does, which causes all kinds of problems. An example:Generally
matplotlib
handles all this correctly internally, but this only breaks backwards compatibility insofar as users are actually taking the time zone they are getting and using it for something, and those people are getting an object with a famously confusing API (every time I talk about this I get people saying they've been doing it wrong, and even people who know how this works in general don't often understand the details well).Case against
dateutil
In favor of
pytz
, I'll say that it's a very "light" dependency in the sense that it's extremely widely used and is a hard dependency of other libraries likepandas
thatmatplotlib
users are likely to be installing anyway.Additionally, currently
pytz
is faster thandateutil
, and I think does a (somewhat) better job at memoizing function calls. This is something that I'm actively working on indateutil
, and I've already closed the gap in many areas (particularlydateutil.tz.tzutc()
, which is very useful).Summary:
In favor of
dateutil
:tzinfo
interfacefold
In favor of
pytz
:I'll also note that I'm only suggesting that
matplotlib
stop usingpytz
as its default timezone provider, not that all support forpytz
be dropped. Users should still be able to supplydatetime
objects with any validtzinfo
and havematplotlib
work properly.The text was updated successfully, but these errors were encountered: