8000 Fix to_rgba_array() for empty input · matplotlib/matplotlib@9358c5c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9358c5c

Browse files
committed
Fix to_rgba_array() for empty input
1 parent f67d556 commit 9358c5c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/matplotlib/colors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ def to_rgba_array(c, alpha=None):
311311
cbook.warn_deprecated("3.2", message="Using a string of single "
312312
"character colors as a color sequence is "
313313
"deprecated. Use an explicit list instead.")
314-
else:
315-
result = np.array([to_rgba(cc, alpha) for cc in c])
314+
return result
316315

317-
return result
316+
if len(c) == 0:
317+
return np.zeros((0, 4), float)
318+
else:
319+
return np.array([to_rgba(cc, alpha) for cc in c])
318320

319321

320322
def to_rgb(c):

lib/matplotlib/tests/test_colors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ def test_cn():
806806
def test_conversions():
807807
# to_rgba_array("none") returns a (0, 4) array.
808808
assert_array_equal(mcolors.to_rgba_array("none"), np.zeros((0, 4)))
809+
assert_array_equal(mcolors.to_rgba_array([]), np.zeros((0, 4)))
809810
# a list of grayscale levels, not a single color.
810811
assert_array_equal(
811812
mcolors.to_rgba_array([".2", ".5", ".8"]),

0 commit comments

Comments
 (0)
0