Skip to content

Commit 7a3248f

Browse files
authored
Merge pull request matplotlib#10861 from timhoffm/unpy2
More python3 cleanup
2 parents dbfc79c + 3a8b143 commit 7a3248f

File tree

12 files changed

+46
-121
lines changed

12 files changed

+46
-121
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
3-
4-
import six
5-
from six.moves import zip, zip_longest
6-
71
import functools
82
import itertools
93
import logging
@@ -2764,7 +2758,7 @@ def get_next_color():
27642758
if autopct is not None:
27652759
xt = x + pctdistance * radius * math.cos(thetam)
27662760
yt = y + pctdistance * radius * math.sin(thetam)
2767-
if isinstance(autopct, six.string_types):
2761+
if isinstance(autopct, str):
27682762
s = autopct % (100. * frac)
27692763
elif callable(autopct):
27702764
s = autopct(100. * frac)
@@ -5603,8 +5597,7 @@ def pcolor(self, *args, **kwargs):
56035597
# makes artifacts that are often disturbing.
56045598
if 'antialiased' in kwargs:
56055599
kwargs['antialiaseds'] = kwargs.pop('antialiased')
5606-
if 'antialiaseds' not in kwargs and (
5607-
isinstance(ec, six.string_types) and ec.lower() == "none"):
5600+
if 'antialiaseds' not in kwargs and cbook._str_lower_equal(ec, "none"):
56085601
kwargs['antialiaseds'] = False
56095602

56105603
kwargs.setdefault('snap', False)
@@ -6526,12 +6519,12 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65266519

65276520
if label is None:
65286521
labels = [None]
6529-
elif isinstance(label, six.string_types):
6522+
elif isinstance(label, str):
65306523
labels = [label]
65316524
else:
6532-
labels = [six.text_type(lab) for lab in label]
6525+
labels = [str(lab) for lab in label]
65336526

6534-
for patch, lbl in zip_longest(patches, labels, fillvalue=None):
6527+
for patch, lbl in itertools.zip_longest(patches, labels):
65356528
if patch:
65366529
p = patch[0]
65376530
p.update(kwargs)

lib/matplotlib/backends/qt_compat.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
""" A Qt API selector that can be used to switch between PyQt and PySide.
22
"""
3-
from __future__ import (absolute_import, division, print_function,
4-
unicode_literals)
5-
6-
import six
73

84
import os
95
import logging

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
1818
The object-oriented API is recommended for more complex plots.
1919
"""
20-
from __future__ import (absolute_import, division, print_function,
21-
unicode_literals)
22-
23-
import six
2420

2521
import inspect
2622
from numbers import Number
@@ -489,7 +485,7 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
489485
figLabel = ''
490486
if num is None:
491487
num = next_num
492-
elif isinstance(num, six.string_types):
488+
elif isinstance(num, str):
493489
figLabel = num
494490
allLabels = get_figlabels()
495491
if figLabel not in allLabels:
@@ -640,13 +636,13 @@ def close(*args):
640636
arg = args[0]
641637
if arg == 'all':
642638
_pylab_helpers.Gcf.destroy_all()
643-
elif isinstance(arg, six.integer_types):
639+
elif isinstance(arg, int):
644640
_pylab_helpers.Gcf.destroy(arg)
645641
elif hasattr(arg, 'int'):
646642
# if we are dealing with a type UUID, we
647643
# can use its integer representation
648644
_pylab_helpers.Gcf.destroy(arg.int)
649-
elif isinstance(arg, six.string_types):
645+
elif isinstance(arg, str):
650646
allLabels = get_figlabels()
651647
if arg in allLabels:
652648
num = get_fignums()[allLabels.index(arg)]
@@ -2434,7 +2430,7 @@ def plotfile(fname, cols=(0,), plotfuncs=None,
24342430

24352431
def getname_val(identifier):
24362432
'return the name and column data for identifier'
2437-
if isinstance(identifier, six.string_types):
2433+
if isinstance(identifier, str):
24382434
return identifier, r[identifier]
24392435
elif isinstance(identifier, Number):
24402436
name = r.dtype.names[int(identifier)]

lib/matplotlib/testing/jpl_units/Duration.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
# ==========================================================================
1111
# Place all imports after here.
1212
#
13-
from __future__ import (absolute_import, division, print_function,
14-
unicode_literals)
15-
16-
import six
1713
import operator
1814
#
1915
# Place all imports before here.
@@ -66,20 +62,9 @@ def seconds(self):
6662
return self._seconds
6763

6864
# ----------------------------------------------------------------------
69-
def __nonzero__(self):
70-
"""Compare two Durations.
71-
72-
= INPUT VARIABLES
73-
- rhs The Duration to compare against.
74-
75-
= RETURN VALUE
76-
- Returns -1 if self < rhs, 0 if self == rhs, +1 if self > rhs.
77-
"""
65+
def __bool__(self):
7866
return self._seconds != 0
7967

80-
if six.PY3:
81-
__bool__ = __nonzero__
82-
8368
# ----------------------------------------------------------------------
8469
def __eq__(self, rhs):
8570
return self._cmp(rhs, operator.eq)

lib/matplotlib/testing/jpl_units/Epoch.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
# ===========================================================================
1111
# Place all imports after here.
1212
#
13-
from __future__ import (absolute_import, division, print_function,
14-
unicode_literals)
15-
16-
import six
1713
import operator
1814
import math
1915
import datetime as DT
@@ -68,16 +64,18 @@ def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None):
6864
(daynum is not None and dt is not None) or
6965
(dt is not None and (sec is not None or jd is not None)) or
7066
((dt is not None) and not isinstance(dt, DT.datetime))):
71-
msg = "Invalid inputs. Must enter sec and jd together, " \
72-
"daynum by itself, or dt (must be a python datetime).\n" \
73-
"Sec = %s\nJD = %s\ndnum= %s\ndt = %s" \
74-
% (str(sec), str(jd), str(daynum), str(dt))
75-
raise ValueError(msg)
67+
raise ValueError(
68+
"Invalid inputs. Must enter sec and jd together, "
69+
"daynum by itself, or dt (must be a python datetime).\n"
70+
"Sec = %s\n"
71+
"JD = %s\n"
72+
"dnum= %s\n"
73+
"dt = %s" % (sec, jd, daynum, dt))
7674

7775
if frame not in self.allowed:
78-
msg = "Input frame '%s' is not one of the supported frames of %s" \
79-
% (frame, str(list(six.iterkeys(self.allowed))))
80-
raise ValueError(msg)
76+
raise ValueError(
77+
"Input frame '%s' is not one of the supported frames of %s" %
78+
(frame, list(self.allowed.keys())))
8179

8280
self._frame = frame
8381

lib/matplotlib/testing/jpl_units/EpochConverter.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
# ==========================================================================
1111
# Place all imports after here.
1212
#
13-
from __future__ import (absolute_import, division, print_function,
14-
unicode_literals)
15-
16-
import six
17-
1813
import matplotlib.units as units
1914
import matplotlib.dates as date_ticker
2015
from matplotlib.cbook import iterable
@@ -121,8 +116,8 @@ def convert(value, unit, axis):
121116
isNotEpoch = True
122117
isDuration = False
123118

124-
if iterable(value) and not isinstance(value, six.string_types):
125-
if (len(value) == 0):
119+
if iterable(value) and not isinstance(value, str):
120+
if len(value) == 0:
126121
return []
127122
else:
128123
return [EpochConverter.convert(x, unit, axis) for x in value]
@@ -156,7 +151,7 @@ def default_units(value, axis):
156151
- Returns the default units to use for value.
157152
"""
158153
frame = None
159-
if iterable(value) and not isinstance(value, six.string_types):
154+
if iterable(value) and not isinstance(value, str):
160155
return EpochConverter.default_units(value[0], axis)
161156
else:
162157
frame = value.frame()

lib/matplotlib/testing/jpl_units/StrConverter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
# ==========================================================================
1111
# Place all imports after here.
1212
#
13-
from __future__ import (absolute_import, division, print_function,
14-
unicode_literals)
15-
1613
import matplotlib.units as units
1714
from matplotlib.cbook import iterable
18-
15+
#
1916
# Place all imports before here.
2017
# ==========================================================================
2118

lib/matplotlib/testing/jpl_units/UnitDbl.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
# ==========================================================================
1111
# Place all imports after here.
1212
#
13-
from __future__ import (absolute_import, division, print_function,
14-
unicode_literals)
15-
16-
import six
1713
import operator
1814
#
1915
# Place all imports before here.
@@ -111,19 +107,9 @@ def __neg__(self):
111107
return UnitDbl(-self._value, self._units)
112108

113109
# ----------------------------------------------------------------------
114-
def __nonzero__(self):
115-
"""Test a UnitDbl for a non-zero value.
116-
117-
= RETURN VALUE
118-
- Returns true if the value is non-zero.
119-
"""
120-
if six.PY3:
121-
return self._value.__bool__()
122-
else:
123-
return self._value.__nonzero__()
124-
125-
if six.PY3:
126-
__bool__ = __nonzero__
110+
def __bool__(self):
111+
"""Return the truth value of a UnitDbl."""
112+
return bool(self._value)
127113

128114
# ----------------------------------------------------------------------
129115
def __eq__(self, rhs):
@@ -292,9 +278,9 @@ def checkUnits(self, units):
292278
- units The string name of the units to check.
293279
"""
294280
if units not in self.allowed:
295-
msg = "Input units '%s' are not one of the supported types of %s" \
296-
% (units, str(list(six.iterkeys(self.allowed))))
297-
raise ValueError(msg)
281+
raise ValueError("Input units '%s' are not one of the supported "
282+
"types of %s" % (
283+
units, list(self.allowed.keys())))
298284

299285
# ----------------------------------------------------------------------
300286
def checkSameUnits(self, rhs, func):

lib/matplotlib/testing/jpl_units/UnitDblConverter.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
# ==========================================================================
1010
# Place all imports after here.
1111
#
12-
from __future__ import (absolute_import, division, print_function,
13-
unicode_literals)
14-
15-
import six
16-
1712
import numpy as np
1813
import matplotlib.units as units
1914
import matplotlib.projections.polar as polar
@@ -75,11 +70,8 @@ def axisinfo(unit, axis):
7570
# Check to see if the value used for units is a string unit value
7671
# or an actual instance of a UnitDbl so that we can use the unit
7772
# value for the default axis label value.
78-
if (unit):
79-
if (isinstance(unit, six.string_types)):
80-
label = unit
81-
else:
82-
label = unit.label()
73+
if unit:
74+
label = unit if isinstance(unit, str) else unit.label()
8375
else:
8476
label = None
8577

@@ -109,8 +101,8 @@ def convert(value, unit, axis):
109101

110102
isNotUnitDbl = True
111103

112-
if (iterable(value) and not isinstance(value, six.string_types)):
113-
if (len(value) == 0):
104+
if iterable(value) and not isinstance(value, str):
105+
if len(value) == 0:
114106
return []
115107
else:
116108
return [UnitDblConverter.convert(x, unit, axis) for x in value]
@@ -153,7 +145,7 @@ def default_units(value, axis):
153145

154146
# Determine the default units based on the user preferences set for
155147
# default units when printing a UnitDbl.
156-
if (iterable(value) and not isinstance(value, six.string_types)):
148+
if iterable(value) and not isinstance(value, str):
157149
return UnitDblConverter.default_units(value[0], axis)
158150
else:
159151
return UnitDblConverter.defaults[value.type()]

lib/matplotlib/testing/jpl_units/UnitDblFormatter.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
# ==========================================================================
1111
# Place all imports after here.
1212
#
13-
from __future__ import (absolute_import, division, print_function,
14-
unicode_literals)
15-
1613
import matplotlib.ticker as ticker
1714
#
1815
# Place all imports before here.

lib/matplotlib/testing/jpl_units/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
"""
3232

3333
# ======================================================================
34-
from __future__ import (absolute_import, division, print_function,
35-
unicode_literals)
3634

3735
from .Duration import Duration
3836
from .Epoch import Epoch

0 commit comments

Comments
 (0)