|
68 | 68 | from collections.abc import Sized
|
69 | 69 | import functools
|
70 | 70 | import itertools
|
| 71 | +from numbers import Number |
71 | 72 | import re
|
72 | 73 |
|
73 | 74 | import numpy as np
|
@@ -260,16 +261,16 @@ def _to_rgba_no_colorcycle(c, alpha=None):
|
260 | 261 | return c, c, c, alpha if alpha is not None else 1.
|
261 | 262 | raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
|
262 | 263 | # tuple color.
|
263 |
| - c = np.array(c) |
264 |
| - if not np.can_cast(c.dtype, float, "same_kind") or c.ndim != 1: |
265 |
| - # Test the dtype explicitly as `map(float, ...)`, `np.array(..., |
266 |
| - # float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5. |
267 |
| - # Test dimensionality to reject single floats. |
| 264 | + if not np.iterable(c): |
268 | 265 | raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
|
269 |
| - # Return a tuple to prevent the cached value from being modified. |
270 |
| - c = tuple(c.astype(float)) |
271 | 266 | if len(c) not in [3, 4]:
|
272 | 267 | raise ValueError("RGBA sequence should have length 3 or 4")
|
| 268 | + if not all(isinstance(x, Number) for x in c): |
| 269 | + # Checks that don't work: `map(float, ...)`, `np.array(..., float)` and |
| 270 | + # `np.array(...).astype(float)` would all convert "0.5" to 0.5. |
| 271 | + raise ValueError(f"Invalid RGBA argument: {orig_c!r}") |
| 272 | + # Return a tuple to prevent the cached value from being modified. |
| 273 | + c = tuple(map(float, c)) |
273 | 274 | if len(c) == 3 and alpha is None:
|
274 | 275 | alpha = 1
|
275 | 276 | if alpha is not None:
|
|
0 commit comments