Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2d674c

Browse files
committed
Merge pull request #2080 from pelson/cmap_and_norm_levels_test_fix
Fixed failing test on python3.
2 parents 3b2f937 + b72b0f7 commit e2d674c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/matplotlib/tests/test_colors.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def test_cmap_and_norm_from_levels_and_colors2():
122122
clr = mcolors.colorConverter.to_rgba_array(colors)
123123
bad = (0.1, 0.1, 0.1, 0.1)
124124
no_color = (0.0, 0.0, 0.0, 0.0)
125+
masked_value = 'masked value'
125126

126127
# Define the test values which are of interest.
127128
# Note: levels are lev[i] <= v < lev[i+1]
@@ -131,38 +132,40 @@ def test_cmap_and_norm_from_levels_and_colors2():
131132
2.25: clr[2],
132133
3: clr[4],
133134
3.5: clr[4],
134-
np.ma.array(1, mask=True): bad}),
135+
masked_value: bad}),
135136

136137
('min', -1, {-2: clr[0],
137138
-1: clr[1],
138139
2: clr[2],
139140
2.25: clr[2],
140141
3: no_color,
141142
3.5: no_color,
142-
np.ma.array(1, mask=True): bad}),
143+
masked_value: bad}),
143144

144145
('max', -1, {-2: no_color,
145146
-1: clr[0],
146147
2: clr[1],
147148
2.25: clr[1],
148149
3: clr[3],
149150
3.5: clr[3],
150-
np.ma.array(1, mask=True): bad}),
151+
masked_value: bad}),
151152

152153
('neither', -2, {-2: no_color,
153154
-1: clr[0],
154155
2: clr[1],
155156
2.25: clr[1],
156157
3: no_color,
157158
3.5: no_color,
158-
np.ma.array(1, mask=True): bad}),
159+
masked_value: bad}),
159160
]
160161

161162
for extend, i1, cases in tests:
162163
cmap, norm = mcolors.from_levels_and_colors(levels, colors[0:i1],
163164
extend=extend)
164165
cmap.set_bad(bad)
165166
for d_val, expected_color in sorted(cases.items()):
167+
if d_val == masked_value:
168+
d_val = np.ma.array(1, mask=True)
166169
assert_array_equal(expected_color, cmap(norm([d_val]))[0],
167170
'Wih extend={0!r} and data '
168171
'value={1!r}'.format(extend, d_val))

0 commit comments

Comments
 (0)