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

Skip to content

Commit 14a8c6e

Browse files
committed
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.
1 parent 6d3f283 commit 14a8c6e

File tree

4 files changed

+5
-25
lines changed

4 files changed

+5
-25
lines changed

doc/conf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
from datetime import datetime
2121

22-
if sys.version_info < (3, 0, 0):
23-
print("You're using python 2.x, conf.py works with python3+ only.")
24-
exit()
2522
# If your extensions are in another directory, add it here. If the directory
2623
# is relative to the documentation root, use os.path.abspath to make it
2724
# absolute, like shown here.

lib/matplotlib/__init__.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,7 @@
9797
9898
Occasionally the internal documentation (python docstrings) will refer
9999
to MATLAB&reg;, a registered trademark of The MathWorks, Inc.
100-
101100
"""
102-
# NOTE: This file must remain Python 2 compatible for the foreseeable future,
103-
# to ensure that we error out properly for existing editable installs.
104-
105-
import sys
106-
if sys.version_info < (3, 5): # noqa: E402
107-
raise ImportError("""
108-
Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.
109-
Beginning with Matplotlib 3.0, Python 3.5 and above is required.
110-
111-
See Matplotlib `INSTALL.rst` file for more information:
112-
113-
https://github.com/matplotlib/matplotlib/blob/master/INSTALL.rst
114-
115-
""")
116101

117102
import atexit
118103
from collections import namedtuple
@@ -131,6 +116,7 @@
131116
import re
132117
import shutil
133118
import subprocess
119+
import sys
134120
import tempfile
135121

136122
# cbook must import matplotlib only within function

lib/matplotlib/image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,6 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
11671167
l, b, r, t = self.axes.bbox.extents
11681168
width = (round(r) + 0.5) - (round(l) - 0.5)
11691169
height = (round(t) + 0.5) - (round(b) - 0.5)
1170-
# The extra cast-to-int is only needed for python2
11711170
width = int(round(width * magnification))
11721171
height = int(round(height * magnification))
11731172
if self._rgbacache is None:

lib/matplotlib/tests/test_category.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
import matplotlib.pyplot as plt
77
import matplotlib.category as cat
88

9-
# Python2/3 text handling
10-
_to_str = cat.StrCategoryFormatter._text
11-
129

1310
class TestUnitData:
1411
test_cases = [('single', (["hello world"], [0])),
@@ -156,14 +153,14 @@ def test_StrCategoryFormatter(self, ax, ydata):
156153
unit = cat.UnitData(ydata)
157154
labels = cat.StrCategoryFormatter(unit._mapping)
158155
for i, d in enumerate(ydata):
159-
assert labels(i, i) == _to_str(d)
156+
assert labels(i, i) == d
160157

161158
@pytest.mark.parametrize("ydata", cases, ids=ids)
162159
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
163160
def test_StrCategoryFormatterPlot(self, ax, ydata, plotter):
164161
plotter(ax, range(len(ydata)), ydata)
165162
for i, d in enumerate(ydata):
166-
assert ax.yaxis.major.formatter(i, i) == _to_str(d)
163+
assert ax.yaxis.major.formatter(i, i) == d
167164
assert ax.yaxis.major.formatter(i+1, i+1) == ""
168165
assert ax.yaxis.major.formatter(0, None) == ""
169166

@@ -172,7 +169,8 @@ def axis_test(axis, labels):
172169
ticks = list(range(len(labels)))
173170
np.testing.assert_array_equal(axis.get_majorticklocs(), ticks)
174171
graph_labels = [axis.major.formatter(i, i) for i in ticks]
175-
assert graph_labels == [_to_str(l) for l in labels]
172+
# _text also decodes bytes as utf-8.
173+
assert graph_labels == [cat.StrCategoryFormatter._text(l) for l in labels]
176174
assert list(axis.units._mapping.keys()) == [l for l in labels]
177175
assert list(axis.units._mapping.values()) == ticks
178176

0 commit comments

Comments
 (0)