-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: don't assert that matplotlib rejects shorthand hex colors #33262
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
TST: don't assert that matplotlib rejects shorthand hex colors #33262
Conversation
Thanks. What version of matplotlib are you using? And you mentioned that log was from pandas 0.25; is the same issue present with 1.0.3? With this diff from pandas master and matplotlib 3.1.2, it seems like a ValueError is raised when those colors are passed diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py
index 08b33ee547..194d29e291 100644
--- a/pandas/tests/plotting/test_frame.py
+++ b/pandas/tests/plotting/test_frame.py
@@ -2041,11 +2041,10 @@ class TestDataFramePlots(TestPlotBase):
self._check_colors(ax.get_lines(), linecolors=custom_colors)
tm.close()
- with pytest.raises(ValueError):
- # Color contains shorthand hex value results in ValueError
- custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"]
- # Forced show plot
- _check_plot_works(df.plot, color=custom_colors)
+ # Color contains shorthand hex value results in ValueError
+ custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"]
+ # Forced show plot
+ _check_plot_works(df.plot, color=custom_colors)
@pytest.mark.slow
def test_dont_modify_colors(self): That gives # Color contains shorthand hex value results in ValueError
custom_colors = ["#F00", "#00F", "#FF0", "#000", "#FFF"]
# Forced show plot
> _check_plot_works(df.plot, color=custom_colors)
pandas/tests/plotting/test_frame.py:2047:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas/tests/plotting/common.py:549: in _check_plot_works
plt.savefig(path)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/pyplot.py:722: in savefig
res = fig.savefig(*args, **kwargs)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/figure.py:2180: in savefig
self.canvas.print_figure(fname, **kwargs)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/backend_bases.py:2089: in print_figure
**kwargs)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:527: in print_png
FigureCanvasAgg.draw(self)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:388: in draw
self.figure.draw(self.renderer)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/artist.py:38: in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/figure.py:1709: in draw
renderer, self, artists, self.suppressComposite)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/image.py:135: in _draw_list_compositing_images
a.draw(renderer)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/artist.py:38: in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/axes/_base.py:2647: in draw
mimage._draw_list_compositing_images(renderer, self, artists)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/image.py:135: in _draw_list_compositing_images
a.draw(renderer)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/artist.py:38: in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/lines.py:783: in draw
lc_rgba = mcolors.to_rgba(self._color, self._alpha)
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/colors.py:177: in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c = '#F00', 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 c is np.ma.masked:
return (0., 0., 0., 0.)
if isinstance(c, str):
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]
except KeyError:
try:
c = _colors_full_map[c.lower()]
except KeyError:
pass
else:
if len(orig_c) == 1:
cbook.warn_deprecated(
"3.1", message="Support for uppercase "
"single-letter colors is deprecated since Matplotlib "
"%(since)s and will be removed %(removal)s; please "
"use lowercase instead.")
if isinstance(c, str):
# 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))
E ValueError: Invalid RGBA argument: '#F00'
../../Envs/pandas-dev/lib/python3.7/site-packages/matplotlib/colors.py:233: ValueError but I have no idea why we're asserting that matplotlib raises a ValueError. |
Debian unstable (matplotlib 3.2.1, numpy 1.17.4, Python 3.8.2). It occurs in pandas 1.0.3 with Debian patches; I haven't tried master. The matplotlib release notes say this changed in 3.2; I removed the "must fail" tests rather than replacing them with "must work" to keep compatibility with older versions. This test was added by #11293. |
Thanks for tracking down those links. Agreed that these can be removed. |
Don't assert that matplotlib rejects shorthand hex colors, as from 3.2 it accepts them: https://matplotlib.org/users/prev_whats_new/whats_new_3.2.0.html#digit-and-4-digit-hex-colors Author: Rebecca N. Palmer <[email protected]> Forwarded: accepted pandas-dev/pandas#33262 Gbp-Pq: Name matplotlib32_compat.patch
From 3.2 it accepts them.
Test failure log (from Debian's pandas 0.25, so includes other issues we don't now have - this one is DID NOT RAISE).