Thanks to visit codestin.com
Credit goes to github.com

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))

lib/matplotlib/tests/test_dates.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
import tempfile
33
from unittest.mock import Mock
44

5-
import dateutil
5+
import dateutil.tz
6+
import dateutil.rrule
67
import numpy as np
78
import pytest
8-
import pytz
99

1010
from matplotlib.testing.decorators import image_comparison
1111
import matplotlib.pyplot as plt
1212
from matplotlib.cbook import MatplotlibDeprecationWarning
1313
import matplotlib.dates as mdates
1414

1515

16+
def __has_pytz():
17+
try:
18+
import pytz
19+
return True
20+
except ImportError:
21+
return False
22+
23+
1624
def test_date_numpyx():
1725
# test that numpy dates work properly...
1826
base = datetime.datetime(2017, 1, 1)
@@ -180,8 +188,8 @@ def test_RRuleLocator():
180188

181189
def test_RRuleLocator_dayrange():
182190
loc = mdates.DayLocator()
183-
x1 = datetime.datetime(year=1, month=1, day=1, tzinfo=pytz.UTC)
184-
y1 = datetime.datetime(year=1, month=1, day=16, tzinfo=pytz.UTC)
191+
x1 = datetime.datetime(year=1, month=1, day=1, tzinfo=mdates.UTC)
192+
y1 = datetime.datetime(year=1, month=1, day=16, tzinfo=mdates.UTC)
185193
loc.tick_values(x1, y1)
186194
# On success, no overflow error shall be thrown
187195

@@ -482,8 +490,8 @@ def test_date_inverted_limit():
482490

483491
def _test_date2num_dst(date_range, tz_convert):
484492
# Timezones
485-
BRUSSELS = pytz.timezone('Europe/Brussels')
486-
UTC = pytz.UTC
493+
BRUSSELS = dateutil.tz.gettz('Europe/Brussels')
494+
UTC = mdates.UTC
487495

488496
# Create a list of timezone-aware datetime objects in UTC
489497
# Interval is 0b0.0000011 days, to prevent float rounding issues
@@ -575,10 +583,7 @@ def tz_convert(*args):
575583
_test_date2num_dst(pd.date_range, tz_convert)
576584

577585

578-
@pytest.mark.parametrize("attach_tz, get_tz", [
579-
(lambda dt, zi: zi.localize(dt), lambda n: pytz.timezone(n)),
580-
(lambda dt, zi: dt.replace(tzinfo=zi), lambda n: dateutil.tz.gettz(n))])
581-
def test_rrulewrapper(attach_tz, get_tz):
586+
def _test_rrulewrapper(attach_tz, get_tz):
582587
SYD = get_tz('Australia/Sydney')
583588

584589
dtstart = attach_tz(datetime.datetime(2017, 4, 1, 0), SYD)
@@ -593,6 +598,25 @@ def test_rrulewrapper(attach_tz, get_tz):
593598
assert act == exp
594599

595600

601+
def test_rrulewrapper():
602+
def attach_tz(dt, zi):
603+
return dt.replace(tzinfo=zi)
604+
605+
_test_rrulewrapper(attach_tz, dateutil.tz.gettz)
606+
607+
608+
@pytest.mark.pytz
609+
@pytest.mark.skipif(not __has_pytz(), reason="Requires pytz")
610+
def test_rrulewrapper_pytz():
611+
# Test to make sure pytz zones are supported in rrules
612+
import pytz
613+
614+
def attach_tz(dt, zi):
615+
return zi.localize(dt)
616+
617+
_test_rrulewrapper(attach_tz, pytz.timezone)
618+
619+
596620
def test_DayLocator():
597621
with pytest.raises(ValueError):
598622
mdates.DayLocator(interval=-1)

requirements/testing/travis_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ pytest-rerunfailures
1515
pytest-timeout
1616
pytest-xdist
1717
python-dateutil
18-
sphinx
1918
tornado
19+
tox

setupext.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ def get_install_requires(self):
13411341
"kiwisolver>=1.0.1",
13421342
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
13431343
"python-dateutil>=2.1",
1344-
"pytz",
13451344
]
13461345

13471346

tox.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ commands =
1818
pytest --pyargs matplotlib
1919
deps =
2020
pytest
21+
22+
[testenv:pytz]
23+
changedir = /tmp
24+
commands =
25+
pytest -m pytz {toxinidir}
26+
deps =
27+
pytest
28+
pytz

0 commit comments

Comments
 (0)