From 14a8c6e61f76e9d7699474d76748d0edd60220b3 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 5 Dec 2019 16:11:56 +0100 Subject: [PATCH] Remove some references to Py2. The checks in `conf.py` and `matplotlib/__init__.py` are not useful because the files are in fact not Py2-compatible (this has been the case for `__init__.py` for a while...) due to f-strings/nonlocal, so someone trying to run the file on Py2 will get a SyntaxError instead of the error message. In image.py the cast to int remains necessary even on Py3 because round(np.float) returns a np.float, not a np.int. --- doc/conf.py | 3 --- lib/matplotlib/__init__.py | 16 +--------------- lib/matplotlib/image.py | 1 - lib/matplotlib/tests/test_category.py | 10 ++++------ 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 7bbfc2efbe2a..3beabe44eabb 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -19,9 +19,6 @@ from datetime import datetime -if sys.version_info < (3, 0, 0): - print("You're using python 2.x, conf.py works with python3+ only.") - exit() # If your extensions are in another directory, add it here. If the directory # is relative to the documentation root, use os.path.abspath to make it # absolute, like shown here. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 335c31b2ab62..623173a23d6e 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -97,22 +97,7 @@ Occasionally the internal documentation (python docstrings) will refer to MATLAB®, a registered trademark of The MathWorks, Inc. - """ -# NOTE: This file must remain Python 2 compatible for the foreseeable future, -# to ensure that we error out properly for existing editable installs. - -import sys -if sys.version_info < (3, 5): # noqa: E402 - raise ImportError(""" -Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4. -Beginning with Matplotlib 3.0, Python 3.5 and above is required. - -See Matplotlib `INSTALL.rst` file for more information: - - https://github.com/matplotlib/matplotlib/blob/master/INSTALL.rst - -""") import atexit from collections import namedtuple @@ -131,6 +116,7 @@ import re import shutil import subprocess +import sys import tempfile # cbook must import matplotlib only within function diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 65026d6820f9..d1aa8ebaf4e1 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -1167,7 +1167,6 @@ def make_image(self, renderer, magnification=1.0, unsampled=False): l, b, r, t = self.axes.bbox.extents width = (round(r) + 0.5) - (round(l) - 0.5) height = (round(t) + 0.5) - (round(b) - 0.5) - # The extra cast-to-int is only needed for python2 width = int(round(width * magnification)) height = int(round(height * magnification)) if self._rgbacache is None: diff --git a/lib/matplotlib/tests/test_category.py b/lib/matplotlib/tests/test_category.py index 1fa38923d437..609c7a966cd9 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -6,9 +6,6 @@ import matplotlib.pyplot as plt import matplotlib.category as cat -# Python2/3 text handling -_to_str = cat.StrCategoryFormatter._text - class TestUnitData: test_cases = [('single', (["hello world"], [0])), @@ -156,14 +153,14 @@ def test_StrCategoryFormatter(self, ax, ydata): unit = cat.UnitData(ydata) labels = cat.StrCategoryFormatter(unit._mapping) for i, d in enumerate(ydata): - assert labels(i, i) == _to_str(d) + assert labels(i, i) == d @pytest.mark.parametrize("ydata", cases, ids=ids) @pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS) def test_StrCategoryFormatterPlot(self, ax, ydata, plotter): plotter(ax, range(len(ydata)), ydata) for i, d in enumerate(ydata): - assert ax.yaxis.major.formatter(i, i) == _to_str(d) + assert ax.yaxis.major.formatter(i, i) == d assert ax.yaxis.major.formatter(i+1, i+1) == "" assert ax.yaxis.major.formatter(0, None) == "" @@ -172,7 +169,8 @@ def axis_test(axis, labels): ticks = list(range(len(labels))) np.testing.assert_array_equal(axis.get_majorticklocs(), ticks) graph_labels = [axis.major.formatter(i, i) for i in ticks] - assert graph_labels == [_to_str(l) for l in labels] + # _text also decodes bytes as utf-8. + assert graph_labels == [cat.StrCategoryFormatter._text(l) for l in labels] assert list(axis.units._mapping.keys()) == [l for l in labels] assert list(axis.units._mapping.values()) == ticks