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

Skip to content

Commit b78b003

Browse files
committed
refactor: add finite bound check for base class and implemented classes
1 parent 6d03949 commit b78b003

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

lib/matplotlib/scale.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from functools import wraps
3535

3636
import numpy as np
37+
import math
3738

3839
import matplotlib as mpl
3940
from matplotlib import _api, _docstring
@@ -122,8 +123,11 @@ def val_in_range(self, val):
122123
efficient solutions for their domain.
123124
"""
124125
try:
125-
vmin, vmax = self.limit_range_for_scale(val, val, minpos=1e-300)
126-
return vmin == val and vmax == val
126+
if not math.isfinite(val):
127+
return False
128+
else:
129+
vmin, vmax = self.limit_range_for_scale(val, val, minpos=1e-300)
130+
return vmin == val and vmax == val
127131
except (TypeError, ValueError):
128132
return False
129133

@@ -213,9 +217,9 @@ def val_in_range(self, val):
213217
"""
214218
Return whether the value is within the valid range for this scale.
215219
216-
This is True for all values.
220+
This is True for all values, except +-inf and NaN.
217221
"""
218-
return True
222+
return math.isfinite(val)
219223

220224

221225
class FuncTransform(Transform):
@@ -425,9 +429,9 @@ def val_in_range(self, val):
425429
"""
426430
Return whether the value is within the valid range for this scale.
427431
428-
This is True for value(s) > 0
432+
This is True for value(s) > 0 except +inf.
429433
"""
430-
if np.isnan(val):
434+
if not math.isfinite(val):
431435
return False
432436
else:
433437
return val > 0
@@ -613,6 +617,14 @@ def get_transform(self):
613617
"""Return the `.SymmetricalLogTransform` associated with this scale."""
614618
return self._transform
615619

620+
def val_in_range(self, val):
621+
"""
622+
Return whether the value is within the valid range for this scale.
623+
624+
This is True for all values, except +-inf and NaN.
625+
"""
626+
return math.isfinite(val)
627+
616628

617629
class AsinhTransform(Transform):
618630
"""Inverse hyperbolic-sine transformation used by `.AsinhScale`"""
@@ -739,6 +751,14 @@ def set_default_locators_and_formatters(self, axis):
739751
else:
740752
axis.set_major_formatter('{x:.3g}')
741753

754+
def val_in_range(self, val):
755+
"""
756+
Return whether the value is within the valid range for this scale.
757+
758+
This is True for all values, except +-inf and NaN.
759+
"""
760+
return math.isfinite(val)
761+
742762

743763
class LogitTransform(Transform):
744764
input_dims = output_dims = 1

0 commit comments

Comments
 (0)