Skip to content

Commit 9324b27

Browse files
authored
Merge pull request #11360 from pganssle/pytzectomy
ENH: Pytzectomy
2 parents 9555535 + 590ee8e commit 9324b27

File tree

14 files changed

+74
-55
lines changed

14 files changed

+74
-55
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ exclude =
1818
versioneer.py
1919
tools/gh_api.py
2020
tools/github_stats.py
21+
.tox
22+
.eggs
2123

2224
per-file-ignores =
2325
setup.py: E402

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,18 @@ before_script: |
158158
fi
159159
160160
script:
161+
# each script we want to run need to go in it's own section and the program you want
162+
# to fail travis need to be the last thing called
161163
- |
162164
echo "Calling pytest with the following arguments: $PYTEST_ADDOPTS"
163165
python -mpytest
166+
- tox -e pytz
164167
- |
165168
if [[ $RUN_FLAKE8 == 1 ]]; then
166169
flake8 --statistics && echo "Flake8 passed without any issues!"
167170
fi
168171
172+
169173
before_cache: |
170174
rm -rf $HOME/.cache/matplotlib/tex.cache
171175
rm -rf $HOME/.cache/matplotlib/test_cache

INSTALL.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ Matplotlib requires the following dependencies:
144144
* `dateutil <https://pypi.python.org/pypi/python-dateutil>`_ (>= 2.1)
145145
* `kiwisolver <https://github.com/nucleic/kiwi>`_ (>= 1.0.0)
146146
* `pyparsing <https://pyparsing.wikispaces.com/>`_
147-
* `pytz <http://pytz.sourceforge.net/>`_
148147

149148
Optionally, you can also install a number of packages to enable better user
150149
interface toolkits. See :ref:`what-is-a-backend` for more details on the

build_alllocal.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:: This assumes you have installed all the dependencies via conda packages:
22
:: # create a new environment with the required packages
3-
:: conda create -n "matplotlib_build" python=3.5 numpy python-dateutil pyparsing pytz tornado cycler tk libpng zlib freetype
3+
:: conda create -n "matplotlib_build" python=3.5 numpy python-dateutil pyparsing tornado cycler tk libpng zlib freetype
44
:: activate matplotlib_build
55
:: if you want qt backend, you also have to install pyqt
66
:: conda install pyqt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Removed ``pytz`` as a dependency
2+
--------------------------------
3+
4+
Since ``dateutil`` and ``pytz`` both provide time zones, and matplotlib already depends on ``dateutil``, matplotlib will now use ``dateutil`` time zones internally and drop the redundant dependency on ``pytz``. While ``dateutil`` time zones are preferred (and currently recommended in the Python documentation), the explicit use of ``pytz`` zones is still supported.

doc/glossary/index.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ Glossary
9090
language widely used for scripting, application development, web
9191
application servers, scientific computing and more.
9292

93-
pytz
94-
`pytz <http://pythonhosted.org/pytz/>`_ provides the Olson tz
95-
database in Python. it allows accurate and cross platform
96-
timezone calculations and solves the issue of ambiguous times at
97-
the end of daylight savings
98-
9993
Qt
10094
`Qt <https://www.qt.io/>`__ is a cross-platform
10195
application framework for desktop and embedded development.

lib/matplotlib/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ def axis_date(self, tz=None):
17471747
# the registered converter can be selected, and the "units" attribute,
17481748
# which is the timezone, can be set.
17491749
if isinstance(tz, str):
1750-
import pytz
1751-
tz = pytz.timezone(tz)
1750+
import dateutil.tz
1751+
tz = dateutil.tz.gettz(tz)
17521752
self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz))
17531753

17541754
def get_tick_space(self):

lib/matplotlib/dates.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Matplotlib provides sophisticated date plotting capabilities, standing on the
3-
shoulders of python :mod:`datetime`, the add-on modules :mod:`pytz` and
4-
:mod:`dateutil`.
3+
shoulders of python :mod:`datetime` and the add-on module :mod:`dateutil`.
54
65
76
.. _date-format:
@@ -46,19 +45,17 @@
4645
4746
All the Matplotlib date converters, tickers and formatters are timezone aware.
4847
If no explicit timezone is provided, the rcParam ``timezone`` is assumend. If
49-
you want to use a custom time zone, pass a :class:`pytz.timezone` instance
48+
you want to use a custom time zone, pass a :class:`datetime.tzinfo` instance
5049
with the tz keyword argument to :func:`num2date`, :func:`.plot_date`, and any
5150
custom date tickers or locators you create.
52-
See `pytz <http://pythonhosted.org/pytz/>`_ for information on :mod:`pytz` and
53-
timezone handling.
5451
5552
A wide range of specific and general purpose date tick locators and
5653
formatters are provided in this module. See
5754
:mod:`matplotlib.ticker` for general information on tick locators
5855
and formatters. These are described below.
5956
6057
61-
The `dateutil module <https://dateutil.readthedocs.io/en/stable/>`_ provides
58+
The `dateutil module <https://dateutil.readthedocs.io>`_ provides
6259
additional code to handle date ticking, making it easy to place ticks
6360
on any kinds of dates. See examples below.
6461
@@ -110,7 +107,7 @@
110107
:class:`matplotlib.dates.rrulewrapper`. The
111108
:class:`rrulewrapper` is a simple wrapper around a
112109
:class:`dateutil.rrule` (`dateutil
113-
<https://dateutil.readthedocs.io/en/stable/>`_) which allow almost
110+
<https://dateutil.readthedocs.io>`_) which allow almost
114111
arbitrary date tick specifications. See `rrule example
115112
<../gallery/ticks_and_spines/date_demo_rrule.html>`_.
116113
@@ -149,6 +146,7 @@
149146
SECONDLY)
150147
from dateutil.relativedelta import relativedelta
151148
import dateutil.parser
149+
import dateutil.tz
152150
import numpy as np
153151

154152
import matplotlib
@@ -175,23 +173,7 @@
175173
_log = logging.getLogger(__name__)
176174

177175

178-
# Make a simple UTC instance so we don't always have to import
179-
# pytz. From the python datetime library docs:
180-
181-
class _UTC(datetime.tzinfo):
182-
"""UTC"""
183-
184-
def utcoffset(self, dt):
185-
return datetime.timedelta(0)
186-
187-
def tzname(self, dt):
188-
return "UTC"
189-
190-
def dst(self, dt):
191-
return datetime.timedelta(0)
192-
193-
194-
UTC = _UTC()
176+
UTC = datetime.timezone.utc
195177

196178

197179
def _get_rc_timezone():
@@ -201,8 +183,7 @@ def _get_rc_timezone():
201183
s = matplotlib.rcParams['timezone']
202184
if s == 'UTC':
203185
return UTC
204-
import pytz
205-
return pytz.timezone(s)
186+
return dateutil.tz.gettz(s)
206187

207188

208189
"""

lib/matplotlib/sphinxext/tests/test_tinypages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
def test_tinypages(tmpdir):
19+
pytest.importorskip('sphinx')
1920
html_dir = pjoin(str(tmpdir), 'html')
2021
doctree_dir = pjoin(str(tmpdir), 'doctrees')
2122
# Build the pages with warnings turned into errors

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import datetime
66

7-
import pytz
7+
import dateutil.tz as dutz
88

99
import numpy as np
1010
from numpy import ma
@@ -5333,8 +5333,9 @@ def test_bar_uint8():
53335333
@image_comparison(baseline_images=['date_timezone_x'], extensions=['png'])
53345334
def test_date_timezone_x():
53355335
# Tests issue 5575
5336-
time_index = [pytz.timezone('Canada/Eastern').localize(datetime.datetime(
5337-
year=2016, month=2, day=22, hour=x)) for x in range(3)]
5336+
time_index = [datetime.datetime(2016, 2, 22, hour=x,
5337+
tzinfo=dutz.gettz('Canada/Eastern'))
5338+
for x in range(3)]
53385339

53395340
# Same Timezone
53405341
fig = plt.figure(figsize=(20, 12))
@@ -5350,8 +5351,9 @@ def test_date_timezone_x():
53505351
extensions=['png'])
53515352
def test_date_timezone_y():
53525353
# Tests issue 5575
5353-
time_index = [pytz.timezone('Canada/Eastern').localize(datetime.datetime(
5354-
year=2016, month=2, day=22, hour=x)) for x in range(3)]
5354+
time_index = [datetime.datetime(2016, 2, 22, hour=x,
5355+
tzinfo=dutz.gettz('Canada/Eastern'))
5356+
for x in range(3)]
53555357

53565358
# Same Timezone
53575359
fig = plt.figure(figsize=(20, 12))
@@ -5368,8 +5370,9 @@ def test_date_timezone_y():
53685370
extensions=['png'])
53695371
def test_date_timezone_x_and_y():
53705372
# Tests issue 5575
5371-
time_index = [pytz.timezone('UTC').localize(datetime.datetime(
5372-
year=2016, month=2, day=22, hour=x)) for x in range(3)]
5373+
UTC = datetime.timezone.utc
5374+
time_index = [datetime.datetime(2016, 2, 22, hour=x, tzinfo=UTC)
5375+
for x in range(3)]
53735376

53745377
# Same Timezone
53755378
fig = plt.figure(figsize=(20, 12))

0 commit comments

Comments
 (0)