Skip to content

Commit b33ba05

Browse files
committed
compile nth color re; fast path for int in isfinite
1 parent 750dcef commit b33ba05

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/matplotlib/cbook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,8 @@ def _safe_first_finite(obj, *, skip_nonfinite=True):
16351635
def safe_isfinite(val):
16361636
if val is None:
16371637
return False
1638+
if isinstance(val, int):
1639+
return True
16381640
try:
16391641
return np.isfinite(val) if np.isscalar(val) else True
16401642
except TypeError:

lib/matplotlib/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ def _sanitize_extrema(ex):
210210
ret = float(ex)
211211
return ret
212212

213+
_nth_color_re = re.compile(r"\AC[0-9]+\Z")
213214

214215
def _is_nth_color(c):
215216
"""Return whether *c* can be interpreted as an item in the color cycle."""
216-
return isinstance(c, str) and re.match(r"\AC[0-9]+\Z", c)
217+
return isinstance(c, str) and _nth_color_re.match(c)
217218

218219

219220
def is_color_like(c):

0 commit comments

Comments
 (0)