8000 Fix spectral/spectral_r deprecations on Python 2.7. · matplotlib/matplotlib@e214769 · GitHub
[go: up one dir, main page]

Skip to content

Commit e214769

Browse files
committed
Fix spectral/spectral_r deprecations on Python 2.7.
In 2.7, the hidden __warningregistry__ gets set and then the warning is never seen again, regardless of the filter setting. Instead, just never trigger the warning in the first place (thanks @anntzer).
1 parent d6149e1 commit e214769

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

lib/matplotlib/cm.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import six
1111

1212
import os
13-
import warnings as _warnings # To remove once spectral is removed
1413
import numpy as np
1514
from numpy import ma
1615
import matplotlib as mpl
@@ -69,7 +68,8 @@ def _generate_cmap(name, lutsize):
6968
"""Generates the requested cmap from its *name*. The lut size is
7069
*lutsize*."""
7170

72-
spec = datad[name]
71+
# Use superclass method to avoid deprecation warnings during initial load.
72+
spec = dict.__getitem__(datad, name)
7373

7474
# Generate the colormap object.
7575
if 'red' in spec:
@@ -81,19 +81,15 @@ def _generate_cmap(name, lutsize):
8181

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

84-
# We silence warnings here to avoid raising the deprecation warning for
85-
# spectral/spectral_r when this module is imported.
86-
with _warnings.catch_warnings():
87-
_warnings.simplefilter("ignore")
88-
# Generate the reversed specifications (all at once, to avoid
89-
# modify-when-iterating).
90-
datad.update({cmapname + '_r': _reverse_cmap_spec(spec)
91-
for cmapname, spec in six.iteritems(datad)})
92-
93-
# Precache the cmaps with ``lutsize = LUTSIZE``.
94-
# Also add the reversed ones added in the section above:
95-
for cmapname in datad:
96-
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
84+
# Generate the reversed specifications (all at once, to avoid
85+
# modify-when-iterating).
86+
datad.update({cmapname + '_r': _reverse_cmap_spec(spec)
87+
for cmapname, spec in six.iteritems(datad)})
88+
89+
# Precache the cmaps with ``lutsize = LUTSIZE``.
90+
# Also add the reversed ones added in the section above:
91+
for cmapname in datad:
92+
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
9793

9894
cmap_d.update(cmaps_listed)
9995

0 commit comments

Comments
 (0)
0