8000 Merge pull request #25203 from oscargus/numberstoreal · matplotlib/matplotlib@b4bb0c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4bb0c1

Browse files
authored
Merge pull request #25203 from oscargus/numberstoreal
Replace checking Number with Real
2 parents 7f6f8cd + 1d96a69 commit b4bb0c1

File tree

9 files changed

+21
-22
lines changed

9 files changed

+21
-22
lines changed

lib/matplotlib/artist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import inspect
55
from inspect import Signature, Parameter
66
import logging
7-
from numbers import Number
7+
from numbers import Number, Real
88
import re
99
import warnings
1010

@@ -1013,7 +1013,7 @@ def set_alpha(self, alpha):
10131013
alpha : scalar or None
10141014
*alpha* must be within the 0-1 range, inclusive.
10151015
"""
1016-
if alpha is not None and not isinstance(alpha, Number):
1016+
if alpha is not None and not isinstance(alpha, Real):
10171017
raise TypeError(
10181018
f'alpha must be numeric or None, not {type(alpha)}')
10191019
if alpha is not None and not (0 <= alpha <= 1):

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import itertools
33
import logging
44
import math
5-
from numbers import Integral, Number
5+
from numbers import Integral, Number, Real
66

77
import numpy as np
88
from numpy import ma
@@ -582,7 +582,7 @@ def invert(x):
582582
secax.set_xlabel('Period [s]')
583583
plt.show()
584584
"""
585-
if location in ['top', 'bottom'] or isinstance(location, Number):
585+
if location in ['top', 'bottom'] or isinstance(location, Real):
586586
secondary_ax = SecondaryAxis(self, 'x', location, functions,
587587
**kwargs)
588588
self.add_child_axes(secondary_ax)
@@ -614,7 +614,7 @@ def secondary_yaxis(self, location, *, functions=None, **kwargs):
614614
np.rad2deg))
615615
secax.set_ylabel('radians')
616616
"""
617-
if location in ['left', 'right'] or isinstance(location, Number):
617+
if location in ['left', 'right'] or isinstance(location, Real):
618618
secondary_ax = SecondaryAxis(self, 'y', location,
619619
functions, **kwargs)
620620
self.add_child_axes(secondary_ax)
@@ -3219,7 +3219,7 @@ def get_next_color():
32193219

32203220
hatch_cycle = itertools.cycle(np.atleast_1d(hatch))
32213221

3222-
_api.check_isinstance(Number, radius=radius, startangle=startangle)
3222+
_api.check_isinstance(Real, radius=radius, startangle=startangle)
32233223
if radius <= 0:
32243224
raise ValueError(f'radius must be a positive number, not {radius}')
32253225

@@ -4188,7 +4188,7 @@ def do_patch(xs, ys, **kwargs):
41884188
raise ValueError(datashape_message.format("positions"))
41894189

41904190
positions = np.array(positions)
4191-
if len(positions) > 0 and not isinstance(positions[0], Number):
4191+
if len(positions) > 0 and not all(isinstance(p, Real) for p in positions):
41924192
raise TypeError("positions should be an iterable of numbers")
41934193

< 628C /code>
41944194
# width

lib/matplotlib/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import datetime
66
import functools
77
import logging
8-
from numbers import Number
8+
from numbers import Real
99

1010
import numpy as np
1111

@@ -1901,7 +1901,7 @@ def set_pickradius(self, pickradius):
19011901
The acceptance radius for containment tests.
19021902
See also `.Axis.contains`.
19031903
"""
1904-
if not isinstance(pickradius, Number) or pickradius < 0:
1904+
if not isinstance(pickradius, Real) or pickradius < 0:
19051905
raise ValueError("pick radius should be a distance")
19061906
self._pickradius = pickradius
19071907

lib/matplotlib/colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import inspect
4747
import io
4848
import itertools
49-
from numbers import Number
49+
from numbers import Real
5050
import re
5151
from PIL import Image
5252
from PIL.PngImagePlugin import PngInfo
@@ -381,7 +381,7 @@ def _to_rgba_no_colorcycle(c, alpha=None):
381381
raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
382382
if len(c) not in [3, 4]:
383383
raise ValueError("RGBA sequence should have length 3 or 4")
384-
if not all(isinstance(x, Number) for x in c):
384+
if not all(isinstance(x, Real) for x in c):
385385
# Checks that don't work: `map(float, ...)`, `np.array(..., float)` and
386386
# `np.array(...).astype(float)` would all convert "0.5" to 0.5.
387387
raise ValueError(f"Invalid RGBA argument: {orig_c!r}")

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def set_pickradius(self, pickradius):
514514
pickradius : float
515515
Pick radius, in points.
516516
"""
517-
if not isinstance(pickradius, Number) or pickradius < 0:
517+
if not isinstance(pickradius, Real) or pickradius < 0:
518518
raise ValueError("pick radius should be a distance")
519519
self._pickradius = pickradius
520520

lib/matplotlib/patches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import functools
66
import inspect
77
import math
8-
from numbers import Number
8+
from numbers import Number, Real
99
import textwrap
1010
from types import SimpleNamespace
1111
from collections import namedtuple
@@ -769,7 +769,7 @@ def rotation_point(self):
769769
def rotation_point(self, value):
770770
if value in ['center', 'xy'] or (
771771
isinstance(value, tuple) and len(value) == 2 and
772-
isinstance(value[0], Number) and isinstance(value[1], Number)
772+
isinstance(value[0], Real) and isinstance(value[1], Real)
773773
):
774774
self._rotation_point = value
775775
else:

lib/matplotlib/pyplot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import importlib
4242
import inspect
4343
import logging
44-
from numbers import Number
4544
import re
4645
import sys
4746
import threading

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import ast
1717
from functools import lru_cache, reduce
18-
from numbers import Number
18+
from numbers import Real
1919
import operator
2020
import os
2121
import re
@@ -475,9 +475,9 @@ def _is_iterable_not_string_like(x):
475475
offset = 0
476476
onoff = ls
477477

478-
if (isinstance(offset, Number)
478+
if (isinstance(offset, Real)
479479
and len(onoff) % 2 == 0
480-
and all(isinstance(elem, Number) for elem in onoff)):
480+
and all(isinstance(elem, Real) for elem in onoff)):
481481
return (offset, onoff)
482482

483483
raise ValueError(f"linestyle {ls!r} is not a valid on-off ink sequence.")

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class (or others) to determine the size of each Axes. The unit
99
values are used.
1010
"""
1111

12-
from numbers import Number
12+
from numbers import Real
1313

1414
from matplotlib import _api
1515
from matplotlib.axes import Axes
@@ -55,7 +55,7 @@ class Fixed(_Base):
5555
"""
5656

5757
def __init__(self, fixed_size):
58-
_api.check_isinstance(Number, fixed_size=fixed_size)
58+
_api.check_isinstance(Real, fixed_size=fixed_size)
5959
self.fixed_size = fixed_size
6060

6161
def get_size(self, renderer):
@@ -190,7 +190,7 @@ class Fraction(_Base):
190190
"""
191191

192192
def __init__(self, fraction, ref_size):
193-
_api.check_isinstance(Number, fraction=fraction)
193+
_api.check_isinstance(Real, fraction=fraction)
194194
self._fraction_ref = ref_size
195195
self._fraction = fraction
196196

@@ -231,7 +231,7 @@ def from_any(size, fraction_ref=None):
231231
>>> a = Size.from_any(1.2) # => Size.Fixed(1.2)
232232
>>> Size.from_any("50%", a) # => Size.Fraction(0.5, a)
233233
"""
234-
if isinstance(size, Number):
234+
if isinstance(size, Real):
235235
return Fixed(size)
236236
elif isinstance(size, str):
237237
if size[-1] == "%":

0 commit comments

Comments
 (0)
0