Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit1f923d4

Browse files
committed
Replace is_numlike by isinstance(..., numbers.Number).
Since we bumped the min numpy version to 1.10, numpy scalars are nowalso instances of numbers.Number.
1 parent3d929fc commit1f923d4

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
importitertools
99
importlogging
1010
importmath
11+
fromnumbersimportNumber
1112
importwarnings
1213

1314
importnumpyasnp
@@ -6526,7 +6527,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65266527
m[:]= (m/db)/tops[-1].sum()
65276528
ifcumulative:
65286529
slc=slice(None)
6529-
ifcbook.is_numlike(cumulative)andcumulative<0:
6530+
ifisinstance(cumulative,Number)andcumulative<0:
65306531
slc=slice(None,None,-1)
65316532

65326533
ifdensity:

‎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
returnnotisinstance(obj,six.string_types)andnotiterable(obj)
582582

583583

584+
@deprecated('3.0','isinstance(..., numbers.Number)')
584585
defis_numlike(obj):
585586
"""return true if *obj* looks like a number"""
586587
returnisinstance(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
importsix
1717
fromsix.movesimportzip
18+
19+
fromnumbersimportNumber
1820
try:
1921
frommathimportgcd
2022
exceptImportError:
@@ -370,7 +372,7 @@ def contains(self, mouseevent):
370372

371373
pickradius= (
372374
float(self._picker)
373-
ifcbook.is_numlike(self._picker)and
375+
ifisinstance(self._picker,Number)and
374376
self._pickerisnotTrue# the bool, not just nonzero or 1
375377
elseself._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
importsix
1111

12+
fromnumbersimportNumber
1213
importwarnings
1314

1415
importnumpyasnp
1516

1617
from .importartist,cbook,colorsasmcolors,docstring,rcParams
1718
from .artistimportArtist,allow_rasterization
1819
from .cbookimport (
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 .markersimportMarkerStyle
2223
from .pathimportPath
@@ -421,7 +422,7 @@ def __init__(self, xdata, ydata,
421422
self.update(kwargs)
422423
self.pickradius=pickradius
423424
self.ind_offset=0
424-
ifis_numlike(self._picker):
425+
ifisinstance(self._picker,Number):
425426
self.pickradius=self._picker
426427

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

459-
ifnotis_numlike(self.pickradius):
460+
ifnotisinstance(self.pickradius,Number):
460461
raiseValueError("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
fromsix.movesimportxrange
9191

9292
fromcollectionsimportSized
93+
fromnumbersimportNumber
9394

9495
importnumpyasnp
9596

96-
from .importrcParams
97-
from .cbookimportis_math_text,is_numlike
97+
from .importcbook,rcParams
9898
from .pathimportPath
9999
from .transformsimportIdentityTransform,Affine2D
100100

@@ -259,7 +259,8 @@ def set_marker(self, marker):
259259
markerinself.markers):
260260
self._marker_function=getattr(
261261
self,'_set_'+self.markers[marker])
262-
elifisinstance(marker,six.string_types)andis_math_text(marker):
262+
elif (isinstance(marker,six.string_types)
263+
andcbook.is_math_text(marker)):
263264
self._marker_function=self._set_mathtext_path
264265
elifisinstance(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-
ifis_numlike(marker[0]):
313+
ifisinstance(marker[0],Number):
313314
iflen(marker)==2:
314315
numsides,rotation=marker[0],0.0
315316
eliflen(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
fromsix.movesimportmap,zip
88

99
importmath
10+
fromnumbersimportNumber
1011
importwarnings
1112

1213
importnumpyasnp
@@ -120,7 +121,7 @@ def get_verts(self):
120121
def_process_radius(self,radius):
121122
ifradiusisnotNone:
122123
returnradius
123-
ifcbook.is_numlike(self._picker):
124+
ifisinstance(self._picker,Number):
124125
_radius=self._picker
125126
else:
126127
ifself.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
importsix
2424

25+
fromnumbersimportNumber
2526
importsys
2627
importtime
2728
importwarnings
@@ -31,9 +32,8 @@
3132
importmatplotlib.colorbar
3233
frommatplotlibimportstyle
3334
frommatplotlibimport_pylab_helpers,interactive
34-
frommatplotlib.cbookimportdedent,silent_list,is_numlike
35-
frommatplotlib.cbookimport_string_to_bool
36-
frommatplotlib.cbookimportdeprecated,warn_deprecated
35+
frommatplotlib.cbookimport (
36+
dedent,deprecated,silent_list,warn_deprecated,_string_to_bool)
3737
frommatplotlibimportdocstring
3838
frommatplotlib.backend_basesimportFigureCanvasBase
3939
frommatplotlib.figureimportFigure,figaspect
@@ -2421,7 +2421,7 @@ def getname_val(identifier):
24212421
'return the name and column data for identifier'
24222422
ifisinstance(identifier,six.string_types):
24232423
returnidentifier,r[identifier]
2424-
elifis_numlike(identifier):
2424+
elifisinstance(identifier,Number):
24252425
name=r.dtype.names[int(identifier)]
24262426
returnname,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
importsix
49-
frommatplotlib.cbookimportiterable,is_numlike,safe_first_element
49+
50+
fromnumbersimportNumber
51+
5052
importnumpyasnp
5153

54+
frommatplotlib.cbookimportiterable,safe_first_element
55+
5256

5357
classAxisInfo(object):
5458
"""
@@ -125,9 +129,9 @@ def is_numlike(x):
125129
"""
126130
ifiterable(x):
127131
forthisxinx:
128-
returnis_numlike(thisx)
132+
returnisinstance(thisx,Number)
129133
else:
130-
returnis_numlike(x)
134+
returnisinstance(x,Number)
131135

132136

133137
classRegistry(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
importsix
55

6+
fromnumbersimportNumber
7+
68
importmatplotlib.axesasmaxes
7-
importmatplotlib.cbookascbook
89
importmatplotlib.tickerasticker
910
frommatplotlib.gridspecimportSubplotSpec
1011

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

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

530531
h= []
531532
v= []
532-
ifisinstance(rect,six.string_types)orcbook.is_numlike(rect):
533+
ifisinstance(rect,(str,Number)):
533534
self._divider=SubplotDivider(fig,rect,horizontal=h,vertical=v,
534535
aspect=aspect)
535536
elifisinstance(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
importsix
1717

18-
importmatplotlib.cbookascbook
18+
fromnumbersimportNumber
19+
1920
frommatplotlib.axesimportAxes
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
returna_rel_size+b_rel_size,a_abs_size+b_abs_size
4648

49+
4750
classAddList(_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
returnrel_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
returnaspect
9195

96+
9297
classAxesX(_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
returnrel_size,abs_size
115120

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

196202

197-
198203
classMaxHeight(_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
returnrel_size,abs_size
241246

247+
242248
classPadded(_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
returnrel_size,abs_size
256262

263+
257264
deffrom_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-
ifcbook.is_numlike(size):
274+
ifisinstance(size,Number):
268275
returnFixed(size)
269276
elifisinstance(size,six.string_types):
270277
ifsize[-1]=="%":
@@ -286,6 +293,7 @@ def get_size(self, renderer):
286293

287294
returnrel_size,abs_size
288295

296+
289297
classGetExtentHelper(object):
290298
def_get_left(tight_bbox,axes_bbox):
291299
returnaxes_bbox.xmin-tight_bbox.xmin

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp