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

Skip to content

Commit 1f923d4

Browse files
committed
Replace is_numlike by isinstance(..., numbers.Number).
Since we bumped the min numpy version to 1.10, numpy scalars are now also instances of numbers.Number.
1 parent 3d929fc commit 1f923d4

File tree

11 files changed

+48
-24
lines changed

11 files changed

+48
-24
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecations
2+
````````````
3+
``cbook.is_numlike`` is deprecated. Use ``isinstance(..., numbers.Number)``
4+
instead.

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import itertools
99
import logging
1010
import math
11+
from numbers import Number
1112
import warnings
1213

1314
import numpy as np
@@ -6526,7 +6527,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65266527
m[:] = (m / db) / tops[-1].sum()
65276528
if cumulative:
65286529
slc = slice(None)
6529-
if cbook.is_numlike(cumulative) and cumulative < 0:
6530+
if isinstance(cumulative, Number) and cumulative < 0:
65306531
slc = slice(None, None, -1)
65316532

65326533
if density:

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ def is_scalar(obj):
581581
return not isinstance(obj, six.string_types) and not iterable(obj)
582582

583583

584+
@deprecated('3.0', 'isinstance(..., numbers.Number)')
584585
def is_numlike(obj):
585586
"""return true if *obj* looks like a number"""
586587
return isinstance(obj, (numbers.Number, np.number))

lib/matplotlib/collections.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import six
1717
from six.moves import zip
18+
19+
from numbers import Number
1820
try:
1921
from math import gcd
2022
except ImportError:
@@ -370,7 +372,7 @@ def contains(self, mouseevent):
370372

371373
pickradius = (
372374
float(self._picker)
373-
if cbook.is_numlike(self._picker) and
375+
if isinstance(self._picker, Number) and
374376
self._picker is not True # the bool, not just nonzero or 1
375377
else self._pickradius)
376378

lib/matplotlib/lines.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
import six
1111

12+
from numbers import Number
1213
import warnings
1314

1415
import numpy as np
1516

1617
from . import artist, cbook, colors as mcolors, docstring, rcParams
1718
from .artist import Artist, allow_rasterization
1819
from .cbook import (
19-
_to_unmasked_float_array, iterable, is_numlike, ls_mapper, ls_mapper_r,
20+
_to_unmasked_float_array, iterable, ls_mapper, ls_mapper_r,
2021
STEP_LOOKUP_MAP)
2122
from .markers import MarkerStyle
2223
from .path import Path
@@ -421,7 +422,7 @@ def __init__(self, xdata, ydata,
421422
self.update(kwargs)
422423
self.pickradius = pickradius
423424
self.ind_offset = 0
424-
if is_numlike(self._picker):
425+
if isinstance(self._picker, Number):
425426
self.pickradius = self._picker
426427

427428
self._xorig = np.asarray([])
@@ -456,7 +457,7 @@ def contains(self, mouseevent):
456457
if callable(self._contains):
457458
return self._contains(self, mouseevent)
458459

459-
if not is_numlike(self.pickradius):
460+
if not isinstance(self.pickradius, Number):
460461
raise ValueError("pick radius should be a distance")
461462

462463
# Make sure we have data to plot

lib/matplotlib/markers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
from six.moves import xrange
9191

9292
from collections import Sized
93+
from numbers import Number
9394

9495
import numpy as np
9596

96-
from . import rcParams
97-
from .cbook import is_math_text, is_numlike
97+
from . import cbook, rcParams
9898
from .path import Path
9999
from .transforms import IdentityTransform, Affine2D
100100

@@ -259,7 +259,8 @@ def set_marker(self, marker):
259259
marker in self.markers):
260260
self._marker_function = getattr(
261261
self, '_set_' + self.markers[marker])
262-
elif isinstance(marker, six.string_types) and is_math_text(marker):
262+
elif (isinstance(marker, six.string_types)
263+
and cbook.is_math_text(marker)):
263264
self._marker_function = self._set_mathtext_path
264265
elif isinstance(marker, Path):
265266
self._marker_function = self._set_path_marker
@@ -309,7 +310,7 @@ def _set_vertices(self):
309310

310311
def _set_tuple_marker(self):
311312
marker = self._marker
312-
if is_numlike(marker[0]):
313+
if isinstance(marker[0], Number):
313314
if len(marker) == 2:
314315
numsides, rotation = marker[0], 0.0
315316
elif len(marker) == 3:

lib/matplotlib/patches.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from six.moves import map, zip
88

99
import math
10+
from numbers import Number
1011
import warnings
1112

1213
import numpy as np
@@ -120,7 +121,7 @@ def get_verts(self):
120121
def _process_radius(self, radius):
121122
if radius is not None:
122123
return radius
123-
if cbook.is_numlike(self._picker):
124+
if isinstance(self._picker, Number):
124125
_radius = self._picker
125126
else:
126127
if self.get_edgecolor()[3] == 0:

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import six
2424

25+
from numbers import Number
2526
import sys
2627
import time
2728
import warnings
@@ -31,9 +32,8 @@
3132
import matplotlib.colorbar
3233
from matplotlib import style
3334
from matplotlib import _pylab_helpers, interactive
34-
from matplotlib.cbook import dedent, silent_list, is_numlike
35-
from matplotlib.cbook import _string_to_bool
36-
from matplotlib.cbook import deprecated, warn_deprecated
35+
from matplotlib.cbook import (
36+
dedent, deprecated, silent_list, warn_deprecated, _string_to_bool)
3737
from matplotlib import docstring
3838
from matplotlib.backend_bases import FigureCanvasBase
3939
from matplotlib.figure import Figure, figaspect
@@ -2421,7 +2421,7 @@ def getname_val(identifier):
24212421
'return the name and column data for identifier'
24222422
if isinstance(identifier, six.string_types):
24232423
return identifier, r[identifier]
2424-
elif is_numlike(identifier):
2424+
elif isinstance(identifier, Number):
24252425
name = r.dtype.names[int(identifier)]
24262426
return name, r[name]
24272427
else:

lib/matplotlib/units.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ def default_units(x, axis):
4646

4747

4848
import six
49-
from matplotlib.cbook import iterable, is_numlike, safe_first_element
49+
50+
from numbers import Number
51+
5052
import numpy as np
5153

54+
from matplotlib.cbook import iterable, safe_first_element
55+
5256

5357
class AxisInfo(object):
5458
"""
@@ -125,9 +129,9 @@ def is_numlike(x):
125129
"""
126130
if iterable(x):
127131
for thisx in x:
128-
return is_numlike(thisx)
132+
return isinstance(thisx, Number)
129133
else:
130-
return is_numlike(x)
134+
return isinstance(x, Number)
131135

132136

133137
class Registry(dict):

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import six
55

6+
from numbers import Number
7+
68
import matplotlib.axes as maxes
7-
import matplotlib.cbook as cbook
89
import matplotlib.ticker as ticker
910
from matplotlib.gridspec import SubplotSpec
1011

@@ -208,7 +209,7 @@ def __init__(self, fig,
208209

209210
h = []
210211
v = []
211-
if isinstance(rect, six.string_types) or cbook.is_numlike(rect):
212+
if isinstance(rect, (str, Number)):
212213
self._divider = SubplotDivider(fig, rect, horizontal=h, vertical=v,
213214
aspect=False)
214215
elif isinstance(rect, SubplotSpec):
@@ -529,7 +530,7 @@ def __init__(self, fig,
529530

530531
h = []
531532
v = []
532-
if isinstance(rect, six.string_types) or cbook.is_numlike(rect):
533+
if isinstance(rect, (str, Number)):
533534
self._divider = SubplotDivider(fig, rect, horizontal=h, vertical=v,
534535
aspect=aspect)
535536
elif isinstance(rect, SubplotSpec):

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ class (or others) to determine the size of each axes. The unit
1515

1616
import six
1717

18-
import matplotlib.cbook as cbook
18+
from numbers import Number
19+
1920
from matplotlib.axes import Axes
2021

22+
2123
class _Base(object):
2224
"Base class"
2325

@@ -44,6 +46,7 @@ def get_size(self, renderer):
4446
b_rel_size, b_abs_size = self._b.get_size(renderer)
4547
return a_rel_size + b_rel_size, a_abs_size + b_abs_size
4648

49+
4750
class AddList(_Base):
4851
def __init__(self, add_list):
4952
self._list = add_list
@@ -75,7 +78,8 @@ def get_size(self, renderer):
7578
abs_size = 0.
7679
return rel_size, abs_size
7780

78-
Scalable=Scaled
81+
Scalable = Scaled
82+
7983

8084
def _get_axes_aspect(ax):
8185
aspect = ax.get_aspect()
@@ -89,6 +93,7 @@ def _get_axes_aspect(ax):
8993

9094
return aspect
9195

96+
9297
class AxesX(_Base):
9398
"""
9499
Scaled size whose relative part corresponds to the data width
@@ -113,6 +118,7 @@ def get_size(self, renderer):
113118
abs_size = 0.
114119
return rel_size, abs_size
115120

121+
116122
class AxesY(_Base):
117123
"""
118124
Scaled size whose relative part corresponds to the data height
@@ -194,7 +200,6 @@ def get_size(self, renderer):
194200
return rel_size, abs_size
195201

196202

197-
198203
class MaxHeight(_Base):
199204
"""
200205
Size whose absolute part is the largest height of
@@ -239,6 +244,7 @@ def get_size(self, renderer):
239244
abs_size = a*self._fraction
240245
return rel_size, abs_size
241246

247+
242248
class Padded(_Base):
243249
"""
244250
Return a instance where the absolute part of *size* is
@@ -254,6 +260,7 @@ def get_size(self, renderer):
254260
abs_size = a + self._pad
255261
return rel_size, abs_size
256262

263+
257264
def from_any(size, fraction_ref=None):
258265
"""
259266
Creates Fixed unit when the first argument is a float, or a
@@ -264,7 +271,7 @@ def from_any(size, fraction_ref=None):
264271
>>> Size.from_any("50%", a) # => Size.Fraction(0.5, a)
265272
266273
"""
267-
if cbook.is_numlike(size):
274+
if isinstance(size, Number):
268275
return Fixed(size)
269276
elif isinstance(size, six.string_types):
270277
if size[-1] == "%":
@@ -286,6 +293,7 @@ def get_size(self, renderer):
286293

287294
return rel_size, abs_size
288295

296+
289297
class GetExtentHelper(object):
290298
def _get_left(tight_bbox, axes_bbox):
291299
return axes_bbox.xmin - tight_bbox.xmin

0 commit comments

Comments
 (0)