Skip to content

Fix regression #5310. Allow assignment of list of numpy arrays to rcp… #5321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ def f(s):
else:
raise
elif type(s) in (list, tuple):
return [scalar_validator(v) for v in s if v]
# The condition on this list comprehension will preserve the
# behavior of filtering out any empty strings (behavior was
# from the original validate_stringlist()), while allowing
# any non-string/text scalar values such as numbers and arrays.
return [scalar_validator(v) for v in s
if not isinstance(v, six.string_types) or v]
else:
msg = "'s' must be of type [ string | list | tuple ]"
raise ValueError(msg)
Expand Down
16 changes: 15 additions & 1 deletion lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import numpy as np
from matplotlib.rcsetup import (validate_bool_maybe_none,
validate_stringlist,
validate_colorlist,
validate_bool,
validate_nseq_int,
validate_nseq_float,
Expand Down Expand Up @@ -245,7 +246,9 @@ def test_Issue_1713():

def _validation_test_helper(validator, arg, target):
res = validator(arg)
if not isinstance(target, Cycler):
if isinstance(target, np.ndarray):
assert_true(np.all(res == target))
elif not isinstance(target, Cycler):
assert_equal(res, target)
else:
# Cyclers can't simply be asserted equal. They don't implement __eq__
Expand Down Expand Up @@ -343,6 +346,17 @@ def test_validators():
(8, ValueError),
('X', ValueError)),
},
{'validator': validate_colorlist,
'success': (('r,g,b', ['r', 'g', 'b']),
(['r', 'g', 'b'], ['r', 'g', 'b']),
('r, ,', ['r']),
(['', 'g', 'blue'], ['g', 'blue']),
([np.array([1, 0, 0]), np.array([0, 1, 0])],
np.array([[1, 0, 0], [0, 1, 0]])),
),
'fail': (('fish', ValueError),
),
}
)

for validator_dict in validation_tests:
Expand Down