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

Skip to content

Commit ca2e557

Browse files
committed
Fix regression #5310. Allow assignment of list of numpy arrays to rcparams
1 parent 0f60fe6 commit ca2e557

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ def f(s):
7979
else:
8080
raise
8181
elif type(s) in (list, tuple):
82-
return [scalar_validator(v) for v in s if v]
82+
# The condition on this list comprehension will preserve the
83+
# behavior of filtering out any empty strings (behavior was
84+
# from the original validate_stringlist()), while allowing
85+
# any non-string/text scalar values such as numbers and arrays.
86+
return [scalar_validator(v) for v in s
87+
if not isinstance(v, six.string_types) or v]
8388
else:
8489
msg = "'s' must be of type [ string | list | tuple ]"
8590
raise ValueError(msg)

lib/matplotlib/tests/test_rcparams.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import numpy as np
2323
from matplotlib.rcsetup import (validate_bool_maybe_none,
2424
validate_stringlist,
25+
validate_colorlist,
2526
validate_bool,
2627
validate_nseq_int,
2728
validate_nseq_float,
@@ -245,7 +246,9 @@ def test_Issue_1713():
245246

246247
def _validation_test_helper(validator, arg, target):
247248
res = validator(arg)
248-
if not isinstance(target, Cycler):
249+
if isinstance(target, np.ndarray):
250+
assert_true(np.all(res == target))
251+
elif not isinstance(target, Cycler):
249252
assert_equal(res, target)
250253
else:
251254
# Cyclers can't simply be asserted equal. They don't implement __eq__
@@ -343,6 +346,17 @@ def test_validators():
343346
(8, ValueError),
344347
('X', ValueError)),
345348
},
349+
{'validator': validate_colorlist,
350+
'success': (('r,g,b', ['r', 'g', 'b']),
351+
(['r', 'g', 'b'], ['r', 'g', 'b']),
352+
('r, ,', ['r']),
353+
(['', 'g', 'blue'], ['g', 'blue']),
354+
([np.array([1, 0, 0]), np.array([0, 1, 0])],
355+
np.array([[1, 0, 0], [0, 1, 0]])),
356+
),
357+
'fail': (('fish', ValueError),
358+
),
359+
}
346360
)
347361

348362
for validator_dict in validation_tests:

0 commit comments

Comments
 (0)