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
New axes.set_prop_cycle method cannot handle any generic iterable #5368
Comments
Can you take a look at how this validation is done? The intention is definitely to take any iterable. Attn @WeatherGod |
Yes, the validation comes about because from matplotlib.rcsetup import cycler instead of using something such as: from cycler import cycler and the version of elif type(s) in (list, tuple): Doing this sort of validating for the input parameters of However, fixing the problem is not a simple matter of replacing
and the logic to handle this is currently in |
That test should probably be replaced with a try/except block once the Can you take a crack at that? On Sat, Oct 31, 2015, 16:51 u55 notifications@github.com wrote:
|
The fix is easy. Use cbook.isiterable instead of checking the types. That
|
@tacaswell @WeatherGod I tried replacing this line: elif type(s) in (list, tuple):
... with this line: import matplotlib.cbook as cbook
elif cbook.iterable(s):
... which fixes the bug, but now this test fails: ...
{'validator': validate_stringlist,
'success': (('', []),
('a,b', ['a', 'b']),
('aardvark', ['aardvark']),
('aardvark, ', ['aardvark']),
('aardvark, ,', ['aardvark']),
(['a', 'b'], ['a', 'b']),
(('a', 'b'), ['a', 'b']),
((1, 2), ['1', '2'])),
'fail': ((dict(), ValueError), # <------- this test fails
(1, ValueError),)
},
... Previously, an empty list would have been validated but an empty dictionary would have raised a ValueError. An empty list must be valid since certain rcParams, such as |
That test has been in there for a long time, And I think an unordered On Sun, Nov 1, 2015 at 7:33 PM, u55 notifications@github.com wrote:
|
The dict should fail because this is expecting a sequence of values, not a mapping. |
Then I'm not sure how to do the test. A numpy.ndarray reports that it is not an instance of >>> import collections
>>> import numpy as np
>>> isinstance(np.arange(9), collections.Sequence)
False |
@tacaswell @WeatherGod try:
import collections.abc as abc
except ImportError:
# python 2
import collections as abc
...
...
elif isinstance(s, abc.Iterable) and not isinstance(s, abc.Mapping):
... This will correctly pass a numpy.ndarray and a generic generator. |
I am ok with that. I still don't like the idea of allowing sets and bags, On Wed, Nov 4, 2015 at 11:23 AM, u55 notifications@github.com wrote:
|
In the case of I think it is a problem that from process-to-process these validators will give different results. |
@tacaswell, note that the validator will convert whatever iterable into a On Wed, Nov 4, 2015 at 11:29 AM, Thomas A Caswell notifications@github.com
|
I am just forseeing lots of very confused bug reports about randomized color cycles. |
Do you really think there are a lot of people keeping configuration values Besides, I think this is a good compromise given that numpy's NDArray is On Wed, Nov 4, 2015 at 11:47 AM, Thomas A Caswell notifications@github.com
|
Do not underestimate users 😜 It is probably worth letting that go through to keep the code simple, can we at least add a big developer warning in code comments summarizing this conversation? |
Sure:
;-) On Wed, Nov 4, 2015 at 11:57 AM, Thomas A Caswell notifications@github.com
|
@u55, I hope the banter between @tacaswell and I didn't discourage you from putting together a pull request with your suggested fix. |
Yeah, no problem. I'm just busy during the week. I'll submit a pull request soon. |
Dear matplotlib developers,
The docstring for the new method
axes.set_prop_cycle
, says that it can take any iterable for the property value. However, I found that it fails with a ValueError if given a numpy.ndarray. Here is a minimal working example:which produces this traceback:
Tested with matplotlib 1.5.0, python 2.7 and python 3.5, running in Arch Linux.
This failure in matplotlib 1.5.0 also affects the method
axes.set_color_cycle
, which is supposed to be deprecated but raises a ValueError instead. The following code worked in matplotlib 1.4.3 but fails in 1.5.0:I think that, for convenience and for backwards compatibility with prior versions of
axes.set_color_cycle
, the new methodaxes.set_prop_cycle
should be able to take any iterable, as the documentation suggests, and not be limited to only a string, list, or tuple.Thank you,
The text was updated successfully, but these errors were encountered: