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

Skip to content

Commit 3476c71

Browse files
committed
Remove support for multiple-color strings in to_rgba_array
1 parent 4b179b9 commit 3476c71

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

lib/matplotlib/colors.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,23 +322,10 @@ def to_rgba_array(c, alpha=None):
322322
except (ValueError, TypeError):
323323
pass
324324

325-
# Convert one at a time.
326325
if isinstance(c, str):
327-
# Single string as color sequence.
328-
# This is deprecated and will be removed in the future.
329-
try:
330-
result = np.array([to_rgba(cc, alpha) for cc in c])
331-
except ValueError as err:
332-
raise ValueError(
333-
"'%s' is neither a valid single color nor a color sequence "
334-
"consisting of single character color specifiers such as "
335-
"'rgb'. Note also that the latter is deprecated." % c) from err
336-
else:
337-
cbook.warn_deprecated(
338-
"3.2", message="Using a string of single character colors as "
339-
"a color sequence is deprecated since %(since)s and will be "
340-
"removed %(removal)s. Use an explicit list instead.")
341-
return result
326+
raise ValueError("Using a string of single character colors as "
327+
"a color sequence is not supported. The colors can "
328+
"be passed as an explicit list instead.")
342329

343330
if len(c) == 0:
344331
return np.zeros((0, 4), float)

lib/matplotlib/tests/test_colors.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,17 +1057,11 @@ def test_to_rgba_array_single_str():
10571057
# single color name is valid
10581058
assert_array_equal(mcolors.to_rgba_array("red"), [(1, 0, 0, 1)])
10591059

1060-
# single char color sequence is deprecated
1061-
with pytest.warns(cbook.MatplotlibDeprecationWarning,
1062-
match="Using a string of single character colors as a "
1063-
"color sequence is deprecated"):
1064-
array = mcolors.to_rgba_array("rgb")
1065-
assert_array_equal(array, [(1, 0, 0, 1), (0, 0.5, 0, 1), (0, 0, 1, 1)])
1066-
1060+
# single char color sequence is invalid
10671061
with pytest.raises(ValueError,
1068-
match="neither a valid single color nor a color "
1069-
"sequence"):
1070-
mcolors.to_rgba_array("rgbx")
1062+
match="Using a string of single character colors as "
1063+
"a color sequence is not supported."):
1064+
array = mcolors.to_rgba_array("rgb")
10711065

10721066

10731067
def test_failed_conversions():

0 commit comments

Comments
 (0)