Skip to content

Deprecate case-insensitive colors. #13211

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
Jan 18, 2019
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
10 changes: 10 additions & 0 deletions doc/api/next_api_changes/2019-01-19-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Deprecations
````````````

Support for passing colors as UPPERCASE strings is deprecated; color names will
become case-sensitive (all-lowercase) after the deprecation period has passed.

The goal is to decrease the number of ambiguous cases when using the ``data``
keyword to plotting methods; e.g. ``plot("X", "Y", data={"X": ..., "Y": ...})``
will not warn about "Y" possibly being a color anymore after the deprecation
period has passed.
12 changes: 10 additions & 2 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,17 @@ def _to_rgba_no_colorcycle(c, alpha=None):
# Named color.
try:
# This may turn c into a non-string, so we check again below.
c = _colors_full_map[c.lower()]
c = _colors_full_map[c]
except KeyError:
pass
try:
c = _colors_full_map[c.lower()]
except KeyError:
pass
else:
cbook.warn_deprecated(
"3.1", message="Support for case-insensitive colors is "
"deprecated since Matplotlib %(since)s and will be "
"removed %(removal)s.")
if isinstance(c, str):
# hex color with no alpha.
match = re.match(r"\A#[a-fA-F0-9]{6}\Z", c)
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6036,3 +6036,11 @@ def test_annotate_across_transforms():
ax.annotate("", xy=(x[150], y[150]), xycoords=ax.transData,
xytext=(1, 0), textcoords=axins.transAxes,
arrowprops=dict(arrowstyle="->"))


def test_deprecated_uppercase_colors():
# Remove after end of deprecation period.
fig, ax = plt.subplots()
with pytest.warns(MatplotlibDeprecationWarning):
ax.plot([1, 2], color="B")
fig.canvas.draw()