Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 88b5bc1

Browse filesBrowse 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.
1 parent cfbf9fd commit 88b5bc1
Copy full SHA for 88b5bc1

File tree

Expand file treeCollapse file tree

1 file changed

+10
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-1
lines changed

‎lib/matplotlib/cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.py
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def _generate_cmap(name, lutsize):
8383

8484
# We silence warnings here to avoid raising the deprecation warning for
8585
# spectral/spectral_r when this module is imported.
86-
with _warnings.catch_warnings():
86+
with _warnings.catch_warnings(record=True):
8787
_warnings.simplefilter("ignore")
88+
_wr = getattr(cbook, '__warningregistry__', None)
8889
# Generate the reversed specifications (all at once, to avoid
8990
# modify-when-iterating).
9091
datad.update({cmapname + '_r': _reverse_cmap_spec(spec)
@@ -95,6 +96,14 @@ def _generate_cmap(name, lutsize):
9596
for cmapname in datad:
9697
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
9798

99+
# Work around Python 2.7 bug. See https://bugs.python.org/issue4180
100+
# and http://stackoverflow.com/q/2390766
101+
if _wr is not None:
102+
cbook.__warningregistry__.clear()
103+
cbook.__warningregistry__.update(_wr)
104+
else:
105+
del cbook.__warningregistry__
106+
98107
cmap_d.update(cmaps_listed)
99108

100109
locals().update(cmap_d)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.