Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dd78552

Browse filesBrowse files
committed
Merge pull request #5321 from WeatherGod/fix_5310
FIX: Allow assignment of list of numpy arrays to rcparam close #5310.
2 parents 3785a36 + ca2e557 commit dd78552
Copy full SHA for dd78552

File tree

Expand file treeCollapse file tree

2 files changed

+21
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-2
lines changed

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+6-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_rcparams.py
+15-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.