I don't think this works
It does work for me (e.g. fix plotting tests in the Diofant), but apparently it breaks some matplotlib tests. I've put an alternative fix in#10031, does that work for you?
Unfortunately, no. Now I see this exception: =================================== FAILURES ===================================____________________________ test_matplotlib_intro _____________________________c = array([[ 0.12156863, 0.46666667, 0.70588235, 1. ]]), alpha = None def to_rgba(c, alpha=None): """Convert `c` to an RGBA color. If `alpha` is not `None`, it forces the alpha value, except if `c` is "none" (case-insensitive), which always maps to `(0, 0, 0, 0)`. """ # Special-case nth color syntax because it should not be cached. if _is_nth_color(c): from matplotlib import rcParams prop_cycler = rcParams['axes.prop_cycle'] colors = prop_cycler.by_key().get('color', ['k']) c = colors[int(c[1]) % len(colors)] try:> rgba = _colors_full_map.cache[c, alpha]E TypeError: unhashable type: 'numpy.ndarray'../../venv/dev/lib/python3.5/site-packages/matplotlib/colors.py:132: TypeErrorDuring handling of the above exception, another exception occurred: @pytest.mark.skipif(matplotlib is None, reason="no matplotlib") def test_matplotlib_intro(): """Examples from the 'introduction' notebook.""" try: name = 'test' tmp_file = TmpFileManager.tmp_file p = plot(x) p = plot(x*sin(x), x*cos(x)) p.extend(p) p[0].line_color = lambda a: a p[1].line_color = 'b' p.title = 'Big title' p.xlabel = 'the x axis' p[1].label = 'straight line' p.legend = True p.aspect_ratio = (1, 1) p.xlim = (-15, 20)> p.save(tmp_file('%s_basic_options_and_colors' % name))diofant/plotting/tests/test_plot.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ diofant/plotting/plot.py:181: in save self._backend.save(path)diofant/plotting/plot.py:966: in save self.process_series()diofant/plotting/plot.py:945: in process_series if self.ax.legend():../../venv/dev/lib/python3.5/site-packages/matplotlib/axes/_axes.py:497: in legend **kwargs)../../venv/dev/lib/python3.5/site-packages/matplotlib/legend.py:1403: in _parse_legend_args handles, labels = _get_legend_handles_labels(axs, handlers)../../venv/dev/lib/python3.5/site-packages/matplotlib/legend.py:1361: in _get_legend_handles_labels and not _in_handles(handle, label)):../../venv/dev/lib/python3.5/site-packages/matplotlib/legend.py:1340: in _in_handles if (colors.to_rgba(f_h.get_color()) != colors.to_rgba(h.get_color())):../../venv/dev/lib/python3.5/site-packages/matplotlib/colors.py:134: in to_rgba rgba = _to_rgba_no_colorcycle(c, alpha)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ c = array([[ 0.12156863, 0.46666667, 0.70588235, 1. ]]), alpha = None def _to_rgba_no_colorcycle(c, alpha=None): """Convert `c` to an RGBA color, with no support for color-cycle syntax. If `alpha` is not `None`, it forces the alpha value, except if `c` is "none" (case-insensitive), which always maps to `(0, 0, 0, 0)`. """ orig_c = c if isinstance(c, six.string_types): if c.lower() == "none": return (0., 0., 0., 0.) # Named color. try: # This may turn c into a non-string, so we check again below. c = _colors_full_map[c.lower()] except KeyError: pass if isinstance(c, six.string_types): # hex color with no alpha. match = re.match(r"\A#[a-fA-F0-9]{6}\Z", c) if match: return (tuple(int(n, 16) / 255 for n in [c[1:3], c[3:5], c[5:7]]) + (alpha if alpha is not None else 1.,)) # hex color with alpha. match = re.match(r"\A#[a-fA-F0-9]{8}\Z", c) if match: color = [int(n, 16) / 255 for n in [c[1:3], c[3:5], c[5:7], c[7:9]]] if alpha is not None: color[-1] = alpha return tuple(color) # string gray. try: return (float(c),) * 3 + (alpha if alpha is not None else 1.,) except ValueError: pass raise ValueError("Invalid RGBA argument: {!r}".format(orig_c)) # tuple color. c = np.array(c) if not np.can_cast(c.dtype, float, "same_kind") or c.ndim != 1: # Test the dtype explicitly as `map(float, ...)`, `np.array(..., # float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5. # Test dimensionality to reject single floats.> raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))E ValueError: Invalid RGBA argument: array([[ 0.12156863, 0.46666667, 0.70588235, 1. ]])../../venv/dev/lib/python3.5/site-packages/matplotlib/colors.py:185: ValueError=============== 1 failed, 4 passed, 2 xfailed in 133.04 seconds ================
(This test coming fromhttps://github.com/diofant/diofant/blob/master/diofant/plotting/tests/test_plot.py). |
PR Summary
This code was introduced in v2.1.1 and, apparently, wasn't tested, because .get_color() returns array.
Here is examples (raises ValueError):
sympy/sympy#13730 (comment)
or
https://travis-ci.org/diofant/diofant/jobs/316670834
PR Checklist