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

Skip to content

Commit 67ae1d9

Browse files
committed
Fix is_color_like for 2-tuple of strings
1 parent 53431a4 commit 67ae1d9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def is_color_like(c):
225225
return True
226226
try:
227227
to_rgba(c)
228-
except ValueError:
228+
except (TypeError, ValueError):
229229
return False
230230
else:
231231
return True

lib/matplotlib/tests/test_colors.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import matplotlib.scale as mscale
2020
from matplotlib.rcsetup import cycler
2121
from matplotlib.testing.decorators import image_comparison, check_figures_equal
22-
from matplotlib.colors import to_rgba_array
22+
from matplotlib.colors import is_color_like, to_rgba_array
2323

2424

2525
@pytest.mark.parametrize('N, result', [
@@ -1702,3 +1702,13 @@ def test_to_rgba_array_none_color_with_alpha_param():
17021702
assert_array_equal(
17031703
to_rgba_array(c, alpha), [[0., 0., 1., 1.], [0., 0., 0., 0.]]
17041704
)
1705+
1706+
1707+
@pytest.mark.parametrize('input, expected',
1708+
[('red', True),
1709+
(('red', 0.5), True),
1710+
(['red', 0.5], False),
1711+
(('red', 'blue'), False),
1712+
(['red', 'blue'], False)])
1713+
def test_is_color_like(input, expected):
1714+
assert is_color_like(input) is expected

0 commit comments

Comments
 (0)