Skip to content

Commit 21fdfed

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 21fdfed

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 number 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):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy