Skip to content

MAINT deprecated 'spectral' in favor of 'nipy_spectral' #7416

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 6 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
MAINT catches deprecation warning when importing cm.py
We don't want to raise the deprecation warning for spectral/spectral_r unless
the user calls that colormap.
  • Loading branch information
NelleV committed Nov 8, 2016
commit c5738e212493aba127a60833001c78a88be346a6
9 changes: 7 additions & 2 deletions lib/matplotlib/_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,12 +1367,17 @@ def gfunc32(x):


class _deprecation_datad(dict):
"""
This class only exists for the purpose of raising an appropriate warning
for the deprecation of spectral. It should be remove in 2.2, once the
colormap spectral disappears.
"""
def __getitem__(self, key):
if key in ["spectral", "spectral_r"]:
warn_deprecated(
"2.0",
name="spectral",
alternative="nipy_spectral",
name="spectral and spectral_r",
alternative="nipy_spectral and nipy_spectral_r",
obj_type="colormap"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to make the message dynamic for spectral_r as well ? I can see pros and cons to both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to be lazy, and not do it, but… maybe I should.

return super(_deprecation_datad, self).__getitem__(key)
Expand Down
29 changes: 17 additions & 12 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import six

import os

import warnings as _warnings # To remove once spectral is removed
import numpy as np
from numpy import ma
import matplotlib as mpl
Expand Down Expand Up @@ -81,17 +81,22 @@ def _generate_cmap(name, lutsize):

LUTSIZE = mpl.rcParams['image.lut']

# Generate the reversed specifications ...
for cmapname in list(six.iterkeys(datad)):
spec = datad[cmapname]
spec_reversed = _reverse_cmap_spec(spec)
datad[cmapname + '_r'] = spec_reversed

# Precache the cmaps with ``lutsize = LUTSIZE`` ...

# Use datad.keys() to also add the reversed ones added in the section above:
for cmapname in six.iterkeys(datad):
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
# We silence warnings here to avoid raising the deprecation warning for
# spectral/spectral_r when this module is imported.
with _warnings.catch_warnings():
_warnings.simplefilter("ignore")
# Generate the reversed specifications ...
for cmapname in list(six.iterkeys(datad)):
spec = datad[cmapname]
spec_reversed = _reverse_cmap_spec(spec)
datad[cmapname + '_r'] = spec_reversed

# Precache the cmaps with ``lutsize = LUTSIZE`` ...

# Use datad.keys() to also add the reversed ones added in the section
# above:
for cmapname in six.iterkeys(datad):
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)

cmap_d.update(cmaps_listed)

Expand Down