Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70cef77

Browse filesBrowse files
authored
Merge pull request #11959 from anntzer/iterableless
cbook.iterable -> np.iterable.
2 parents fb0035f + b67d35f commit 70cef77
Copy full SHA for 70cef77

File tree

Expand file treeCollapse file tree

26 files changed

+106
-106
lines changed
Filter options
Expand file treeCollapse file tree

26 files changed

+106
-106
lines changed

‎doc/api/api_changes/2018-08-17-AL-deprecations.rst renamed to ‎doc/api/next_api_changes/2018-08-17-AL-deprecations.rst

Copy file name to clipboardExpand all lines: doc/api/next_api_changes/2018-08-17-AL-deprecations.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ API deprecations
44
The following API elements are deprecated:
55

66
- ``tk_window_focus``,
7+
- ``cbook.iterable``,
78
- ``mlab.demean``,

‎examples/units/basic_units.py

Copy file name to clipboardExpand all lines: examples/units/basic_units.py
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import matplotlib.units as units
1313
import matplotlib.ticker as ticker
14-
from matplotlib.cbook import iterable
1514

1615

1716
class ProxyDelegate(object):
@@ -345,22 +344,22 @@ def axisinfo(unit, axis):
345344
def convert(val, unit, axis):
346345
if units.ConversionInterface.is_numlike(val):
347346
return val
348-
if iterable(val):
347+
if np.iterable(val):
349348
return [thisval.convert_to(unit).get_value() for thisval in val]
350349
else:
351350
return val.convert_to(unit).get_value()
352351

353352
@staticmethod
354353
def default_units(x, axis):
355354
'return the default unit for x or None'
356-
if iterable(x):
355+
if np.iterable(x):
357356
for thisx in x:
358357
return thisx.unit
359358
return x.unit
360359

361360

362361
def cos(x):
363-
if iterable(x):
362+
if np.iterable(x):
364363
return [math.cos(val.convert_to(radians).get_value()) for val in x]
365364
else:
366365
return math.cos(x.convert_to(radians).get_value())

‎examples/units/evans_test.py

Copy file name to clipboardExpand all lines: examples/units/evans_test.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
to what kind of units client packages use.
1010
"""
1111

12-
from matplotlib.cbook import iterable
12+
import numpy as np
13+
1314
import matplotlib.units as units
1415
import matplotlib.ticker as ticker
1516
import matplotlib.pyplot as plt
@@ -49,15 +50,15 @@ def convert(obj, unit, axis):
4950
if units.ConversionInterface.is_numlike(obj):
5051
return obj
5152

52-
if iterable(obj):
53+
if np.iterable(obj):
5354
return [o.value(unit) for o in obj]
5455
else:
5556
return obj.value(unit)
5657

5758
@staticmethod
5859
def default_units(x, axis):
5960
'return the default unit for x or None'
60-
if iterable(x):
61+
if np.iterable(x):
6162
for thisx in x:
6263
return thisx.unit
6364
else:

‎lib/matplotlib/animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/animation.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
16431643
self._iter_gen = itertools.count
16441644
elif callable(frames):
16451645
self._iter_gen = frames
1646-
elif cbook.iterable(frames):
1646+
elif np.iterable(frames):
16471647
self._iter_gen = lambda: iter(frames)
16481648
if hasattr(frames, '__len__'):
16491649
self.save_count = len(frames)

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ def __init__(self, o):
11751175
responsibility to make sure this is so.
11761176
"""
11771177
if not isinstance(o, Artist):
1178-
if cbook.iterable(o):
1178+
if np.iterable(o):
11791179
o = list(o)
11801180
if len(o):
11811181
o = o[0]

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+21-22Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import matplotlib.ticker as mticker
3434
import matplotlib.transforms as mtransforms
3535
import matplotlib.tri as mtri
36-
from matplotlib.cbook import iterable
3736
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
3837
from matplotlib.axes._base import _AxesBase, _process_plot_format
3938

@@ -1035,11 +1034,11 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
10351034
xmin = self.convert_xunits(xmin)
10361035
xmax = self.convert_xunits(xmax)
10371036

1038-
if not iterable(y):
1037+
if not np.iterable(y):
10391038
y = [y]
1040-
if not iterable(xmin):
1039+
if not np.iterable(xmin):
10411040
xmin = [xmin]
1042-
if not iterable(xmax):
1041+
if not np.iterable(xmax):
10431042
xmax = [xmax]
10441043

10451044
y, xmin, xmax = cbook.delete_masked_points(y, xmin, xmax)
@@ -1113,11 +1112,11 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
11131112
ymin = self.convert_yunits(ymin)
11141113
ymax = self.convert_yunits(ymax)
11151114

1116-
if not iterable(x):
1115+
if not np.iterable(x):
11171116
x = [x]
1118-
if not iterable(ymin):
1117+
if not np.iterable(ymin):
11191118
ymin = [ymin]
1120-
if not iterable(ymax):
1119+
if not np.iterable(ymax):
11211120
ymax = [ymax]
11221121

11231122
x, ymin, ymax = cbook.delete_masked_points(x, ymin, ymax)
@@ -1243,9 +1242,9 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12431242
lineoffsets = self.convert_yunits(lineoffsets)
12441243
linelengths = self.convert_yunits(linelengths)
12451244

1246-
if not iterable(positions):
1245+
if not np.iterable(positions):
12471246
positions = [positions]
1248-
elif any(iterable(position) for position in positions):
1247+
elif any(np.iterable(position) for position in positions):
12491248
positions = [np.asanyarray(position) for position in positions]
12501249
else:
12511250
positions = [np.asanyarray(positions)]
@@ -1259,15 +1258,15 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12591258
linewidths = cbook.local_over_kwdict(linewidths, kwargs, 'linewidth')
12601259
linestyles = cbook.local_over_kwdict(linestyles, kwargs, 'linestyle')
12611260

1262-
if not iterable(lineoffsets):
1261+
if not np.iterable(lineoffsets):
12631262
lineoffsets = [lineoffsets]
1264-
if not iterable(linelengths):
1263+
if not np.iterable(linelengths):
12651264
linelengths = [linelengths]
1266-
if not iterable(linewidths):
1265+
if not np.iterable(linewidths):
12671266
linewidths = [linewidths]
1268-
if not iterable(colors):
1267+
if not np.iterable(colors):
12691268
colors = [colors]
1270-
if hasattr(linestyles, 'lower') or not iterable(linestyles):
1269+
if hasattr(linestyles, 'lower') or not np.iterable(linestyles):
12711270
linestyles = [linestyles]
12721271

12731272
lineoffsets = np.asarray(lineoffsets)
@@ -3065,18 +3064,18 @@ def errorbar(self, x, y, yerr=None, xerr=None,
30653064
ecolor = base_style['color']
30663065
# make sure all the args are iterable; use lists not arrays to
30673066
# preserve units
3068-
if not iterable(x):
3067+
if not np.iterable(x):
30693068
x = [x]
30703069

3071-
if not iterable(y):
3070+
if not np.iterable(y):
30723071
y = [y]
30733072

30743073
if xerr is not None:
3075-
if not iterable(xerr):
3074+
if not np.iterable(xerr):
30763075
xerr = [xerr] * len(x)
30773076

30783077
if yerr is not None:
3079-
if not iterable(yerr):
3078+
if not np.iterable(yerr):
30803079
yerr = [yerr] * len(y)
30813080

30823081
# make the style dict for the 'normal' plot line
@@ -3168,7 +3167,7 @@ def extract_err(err, data):
31683167
except (TypeError, ValueError):
31693168
pass
31703169
else:
3171-
if iterable(a) and iterable(b):
3170+
if np.iterable(a) and np.iterable(b):
31723171
# using list comps rather than arrays to preserve units
31733172
low = [thisx - thiserr for thisx, thiserr
31743173
in cbook.safezip(data, a)]
@@ -4437,7 +4436,7 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
44374436
x, y, C = cbook.delete_masked_points(x, y, C)
44384437

44394438
# Set the size of the hexagon grid
4440-
if iterable(gridsize):
4439+
if np.iterable(gridsize):
44414440
nx, ny = gridsize
44424441
else:
44434442
nx = gridsize
@@ -4632,7 +4631,7 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
46324631
norm.autoscale(accum)
46334632

46344633
if bins is not None:
4635-
if not iterable(bins):
4634+
if not np.iterable(bins):
46364635
minimum, maximum = min(accum), max(accum)
46374636
bins -= 1 # one less edge than bins
46384637
bins = minimum + (maximum - minimum) * np.arange(bins) / bins
@@ -6514,7 +6513,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65146513
bin_range = self.convert_xunits(bin_range)
65156514

65166515
# Check whether bins or range are given explicitly.
6517-
binsgiven = (cbook.iterable(bins) or bin_range is not None)
6516+
binsgiven = np.iterable(bins) or bin_range is not None
65186517

65196518
# We need to do to 'weights' what was done to 'x'
65206519
if weights is not None:

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from matplotlib import cbook, rcParams
1515
from matplotlib.cbook import (
16-
_OrderedSet, _check_1d, _string_to_bool, iterable, index_of, get_label)
16+
_OrderedSet, _check_1d, _string_to_bool, index_of, get_label)
1717
from matplotlib import docstring
1818
import matplotlib.colors as mcolors
1919
import matplotlib.lines as mlines
@@ -3005,7 +3005,7 @@ def set_xbound(self, lower=None, upper=None):
30053005
30063006
.. ACCEPTS: (lower: float, upper: float)
30073007
"""
3008-
if upper is None and iterable(lower):
3008+
if upper is None and np.iterable(lower):
30093009
lower, upper = lower
30103010

30113011
old_lower, old_upper = self.get_xbound()
@@ -3124,7 +3124,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
31243124
>>> set_xlim(5000, 0)
31253125
31263126
"""
3127-
if right is None and iterable(left):
3127+
if right is None and np.iterable(left):
31283128
left, right = left
31293129
if xmin is not None:
31303130
cbook.warn_deprecated('3.0', name='`xmin`',
@@ -3357,7 +3357,7 @@ def set_ybound(self, lower=None, upper=None):
33573357
33583358
.. ACCEPTS: (lower: float, upper: float)
33593359
"""
3360-
if upper is None and iterable(lower):
3360+
if upper is None and np.iterable(lower):
33613361
lower, upper = lower
33623362

33633363
old_lower, old_upper = self.get_ybound()
@@ -3457,7 +3457,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
34573457
34583458
>>> set_ylim(5000, 0)
34593459
"""
3460-
if top is None and iterable(bottom):
3460+
if top is None and np.iterable(bottom):
34613461
bottom, top = bottom
34623462
if ymin is not None:
34633463
cbook.warn_deprecated('3.0', name='`ymin`',

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ class is even handier, and prettier to use. Whenever you want to
327327
pass
328328

329329

330+
@deprecated('3.1', alternative='np.iterable')
330331
def iterable(obj):
331332
"""return true if *obj* is iterable"""
332333
try:
@@ -415,7 +416,7 @@ def open_file_cm(path_or_file, mode="r", encoding=None):
415416

416417
def is_scalar_or_string(val):
417418
"""Return whether the given object is a scalar or string like."""
418-
return isinstance(val, str) or not iterable(val)
419+
return isinstance(val, str) or not np.iterable(val)
419420

420421

421422
def _string_to_bool(s):
@@ -1026,7 +1027,7 @@ def delete_masked_points(*args):
10261027
margs = []
10271028
seqlist = [False] * len(args)
10281029
for i, x in enumerate(args):
1029-
if not isinstance(x, str) and iterable(x) and len(x) == nrecs:
1030+
if not isinstance(x, str) and np.iterable(x) and len(x) == nrecs:
10301031
seqlist[i] = True
10311032
if isinstance(x, np.ma.MaskedArray):
10321033
if x.ndim > 1:

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def __init__(self, ax, cmap=None,
388388
self.ticklocation = ticklocation
389389

390390
self.set_label(label)
391-
if cbook.iterable(ticks):
391+
if np.iterable(ticks):
392392
self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
393393
else:
394394
self.locator = ticks # Handle default in _ticker()
@@ -559,7 +559,7 @@ def set_ticks(self, ticks, update_ticks=True):
559559
use :meth:`update_ticks` to manually update the ticks.
560560
561561
"""
562-
if cbook.iterable(ticks):
562+
if np.iterable(ticks):
563563
self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
564564
else:
565565
self.locator = ticks
@@ -707,9 +707,9 @@ def add_lines(self, levels, colors, linewidths, erase=True):
707707
y = self._locate(levels)
708708
igood = (y < 1.001) & (y > -0.001)
709709
y = y[igood]
710-
if cbook.iterable(colors):
710+
if np.iterable(colors):
711711
colors = np.asarray(colors)[igood]
712-
if cbook.iterable(linewidths):
712+
if np.iterable(linewidths):
713713
linewidths = np.asarray(linewidths)[igood]
714714
X, Y = np.meshgrid([0, 1], y)
715715
if self.orientation == 'vertical':
@@ -1289,7 +1289,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
12891289
anchor = kw.pop('anchor', loc_settings['anchor'])
12901290
parent_anchor = kw.pop('panchor', loc_settings['panchor'])
12911291

1292-
parents_iterable = cbook.iterable(parents)
1292+
parents_iterable = np.iterable(parents)
12931293
# turn parents into a list if it is not already. We do this w/ np
12941294
# because `plt.subplots` can return an ndarray and is natural to
12951295
# pass to `colorbar`.

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def __call__(self, X, alpha=None, bytes=False):
484484
if not self._isinit:
485485
self._init()
486486
mask_bad = None
487-
if not cbook.iterable(X):
487+
if not np.iterable(X):
488488
vtype = 'scalar'
489489
xa = np.array([X])
490490
else:
@@ -716,7 +716,7 @@ def from_list(name, colors, N=256, gamma=1.0):
716716
to divide the range unevenly.
717717
"""
718718

719-
if not cbook.iterable(colors):
719+
if not np.iterable(colors):
720720
raise ValueError('colors must be iterable')
721721

722722
if (isinstance(colors[0], Sized) and len(colors[0]) == 2
@@ -812,7 +812,7 @@ def __init__(self, colors, name='from_list', N=None):
812812
if isinstance(colors, str):
813813
self.colors = [colors] * N
814814
self.monochrome = True
815-
elif cbook.iterable(colors):
815+
elif np.iterable(colors):
816816
if len(colors) == 1:
817817
self.monochrome = True
818818
self.colors = list(
@@ -907,7 +907,7 @@ def process_value(value):
907907
Experimental; we may want to add an option to force the
908908
use of float32.
909909
"""
910-
is_scalar = not cbook.iterable(value)
910+
is_scalar = not np.iterable(value)
911911
if is_scalar:
912912
value = [value]
913913
dtype = np.min_scalar_type(value)
@@ -962,7 +962,7 @@ def inverse(self, value):
962962
(vmin,), _ = self.process_value(self.vmin)
963963
(vmax,), _ = self.process_value(self.vmax)
964964

965-
if cbook.iterable(value):
965+
if np.iterable(value):
966966
val = np.ma.asarray(value)
967967
return vmin + val * (vmax - vmin)
968968
else:
@@ -1035,7 +1035,7 @@ def inverse(self, value):
10351035
raise ValueError("Not invertible until scaled")
10361036
vmin, vmax = self.vmin, self.vmax
10371037

1038-
if cbook.iterable(value):
1038+
if np.iterable(value):
10391039
val = np.ma.asarray(value)
10401040
return vmin * np.ma.power((vmax / vmin), val)
10411041
else:
@@ -1222,7 +1222,7 @@ def inverse(self, value):
12221222
gamma = self.gamma
12231223
vmin, vmax = self.vmin, self.vmax
12241224

1225-
if cbook.iterable(value):
1225+
if np.iterable(value):
12261226
val = np.ma.asarray(value)
12271227
return np.ma.power(val, 1. / gamma) * (vmax - vmin) + vmin
12281228
else:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.