File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -71,10 +71,33 @@ def _gen_cmap_d():
71
71
return cmap_d
72
72
73
73
74
+ class _DeprecatedCmapDict (dict ):
75
+ def __getitem__ (self , key ):
76
+ self ._warn_deprecated ()
77
+ return dict .__getitem__ (self , key )
78
+
79
+ def __setitem__ (self , key , val ):
80
+ self ._warn_deprecated ()
81
+ dict .__setitem__ (self , key , val )
82
+
83
+ def get (self , key , default = None ):
84
+ self ._warn_deprecated ()
85
+ return dict .get (self , key , default )
86
+
87
+ def _warn_deprecated (self ):
88
+ cbook .warn_deprecated (
89
+ "3.3" ,
90
+ message = "The global colormaps dictionary is no longer "
91
+ "considered public API." ,
92
+ alternative = "Please use register_cmap() and get_cmap() to "
93
+ "access the contents of the dictionary."
94
+ )
95
+
96
+
74
97
_cmap_d = _gen_cmap_d ()
75
98
locals ().update (_cmap_d )
76
99
# This is no longer considered public API
77
- cmap_d = _cmap_d
100
+ cmap_d = _DeprecatedCmapDict ( _cmap_d )
78
101
79
102
80
103
# Continue with definitions ...
Original file line number Diff line number Diff line change @@ -126,6 +126,17 @@ def test_colormap_global_set_warn():
126
126
plt .register_cmap (cmap = orig_cmap )
127
127
128
128
129
+ def test_colormap_dict_deprecate ():
130
+ # Make sure we warn on get and set access into cmap_d
131
+ with pytest .warns (cbook .MatplotlibDeprecationWarning ,
132
+ match = "The global colormaps dictionary is no longer" ):
133
+ cm = plt .cm .cmap_d ['viridis' ]
134
+
135
+ with pytest .warns (cbook .MatplotlibDeprecationWarning ,
136
+ match = "The global colormaps dictionary is no longer" ):
137
+ plt .cm .cmap_d ['test' ] = cm
138
+
139
+
129
140
def test_colormap_copy ():
130
141
cm = plt .cm .Reds
131
142
cm_copy = copy .copy (cm )
You can’t perform that action at this time.
0 commit comments