Skip to content

Commit a8e028d

Browse files
committed
Merge pull request #3755 from jenshnielsen/numpy_191_fixes
TST : Reenable shading tests for numpy 1.9.1 and later
2 parents cf5b9a7 + 727c1da commit a8e028d

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

lib/matplotlib/tests/test_colors.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ def test_light_source_topo_surface():
258258
ax.set(xticks=[], yticks=[])
259259

260260

261-
@knownfailureif(V(np.__version__) >= V('1.9.0'))
262261
def test_light_source_shading_default():
263262
"""Array comparison test for the default "hsv" blend mode. Ensure the
264263
default result doesn't change without warning."""
@@ -305,11 +304,20 @@ def test_light_source_shading_default():
305304
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
306305
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
307306
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00]]]).T
307+
if (V(np.__version__) == V('1.9.0')):
308+
# Numpy 1.9.0 uses a 2. order algorithm on the edges by default
309+
# This was changed back again in 1.9.1
310+
expect = expect[1:-1, 1:-1, :]
311+
rgb = rgb[1:-1, 1:-1, :]
312+
308313
assert_array_almost_equal(rgb, expect, decimal=2)
309314

310315

311-
@knownfailureif(V(np.__version__) >= V('1.9.0') or
312-
V(np.__version__) < V('1.7.0'))
316+
@knownfailureif((V(np.__version__) <= V('1.9.0')
317+
and V(np.__version__) >= V('1.7.0')))
318+
# Numpy 1.9.1 fixed a bug in masked arrays which resulted in
319+
# additional elements being masked when calculating the gradient thus
320+
# the output is different with earlier numpy versions.
313321
def test_light_source_masked_shading():
314322
"""Array comparison test for a surface with a masked portion. Ensures that
315323
we don't wind up with "fringes" of odd colors around masked regions."""
@@ -323,32 +331,32 @@ def test_light_source_masked_shading():
323331
rgb = ls.shade(z, cmap)
324332

325333
# Result stored transposed and rounded for for more compact display...
326-
expect = np.array([[[1.00, 0.95, 0.96, 0.94, 0.86, 0.67, 0.40, 0.03],
327-
[0.95, 0.99, 1.00, 1.00, 1.00, 0.98, 0.67, 0.19],
328-
[0.96, 1.00, 1.00, 1.00, 1.00, 1.00, 0.78, 0.36],
329-
[0.94, 1.00, 1.00, 0.00, 0.00, 1.00, 0.55, 0.32],
330-
[0.86, 1.00, 1.00, 0.00, 0.00, 1.00, 0.27, 0.14],
331-
[0.67, 0.98, 1.00, 1.00, 1.00, 1.00, 0.07, 0.03],
332-
[0.40, 0.67, 0.78, 0.55, 0.27, 0.07, 0.00, 0.01],
333-
[0.03, 0.19, 0.36, 0.32, 0.14, 0.03, 0.01, 0.00]],
334-
335-
[[1.00, 0.93, 0.93, 0.88, 0.72, 0.50, 0.28, 0.03],
336-
[0.93, 0.97, 0.99, 0.96, 0.87, 0.70, 0.42, 0.11],
337-
[0.93, 0.99, 0.74, 0.78, 0.78, 0.74, 0.45, 0.20],
338-
[0.88, 0.96, 0.78, 0.00, 0.00, 0.78, 0.32, 0.16],
339-
[0.72, 0.87, 0.78, 0.00, 0.00, 0.78, 0.14, 0.06],
340-
[0.50, 0.70, 0.74, 0.78, 0.78, 0.74, 0.03, 0.01],
341-
[0.28, 0.42, 0.45, 0.32, 0.14, 0.03, 0.00, 0.00],
342-
[0.03, 0.11, 0.20, 0.16, 0.06, 0.01, 0.00, 0.00]],
343-
344-
[[1.00, 0.91, 0.91, 0.84, 0.64, 0.39, 0.21, 0.03],
345-
[0.91, 0.96, 0.98, 0.93, 0.77, 0.53, 0.27, 0.06],
346-
[0.91, 0.98, 0.47, 0.50, 0.50, 0.47, 0.25, 0.10],
347-
[0.84, 0.93, 0.50, 0.00, 0.00, 0.50, 0.13, 0.06],
348-
[0.64, 0.77, 0.50, 0.00, 0.00, 0.50, 0.03, 0.01],
349-
[0.39, 0.53, 0.47, 0.50, 0.50, 0.47, 0.00, 0.00],
350-
[0.21, 0.27, 0.25, 0.13, 0.03, 0.00, 0.00, 0.00],
351-
[0.03, 0.06, 0.10, 0.06, 0.01, 0.00, 0.00, 0.00]],
334+
expect = np.array([[[0.90, 0.88, 0.91, 0.91, 0.84, 0.64, 0.36, 0.00],
335+
[0.88, 0.96, 1.00, 1.00, 1.00, 0.97, 0.64, 0.18],
336+
[0.91, 1.00, 1.00, 1.00, 1.00, 1.00, 0.74, 0.34],
337+
[0.91, 1.00, 1.00, 0.00, 0.00, 1.00, 0.52, 0.30],
338+
[0.84, 1.00, 1.00, 0.00, 0.00, 1.00, 0.25, 0.13],
339+
[0.64, 0.97, 1.00, 1.00, 1.00, 0.23, 0.07, 0.03],
340+
[0.36, 0.64, 0.74, 0.52, 0.25, 0.07, 0.00, 0.01],
341+
[0.00, 0.18, 0.34, 0.30, 0.13, 0.03, 0.01, 0.00]],
342+
343+
[[0.90, 0.82, 0.85, 0.82, 0.68, 0.46, 0.24, 0.00],
344+
[0.82, 0.91, 0.95, 0.93, 0.85, 0.68, 0.39, 0.10],
345+
[0.85, 0.95, 1.00, 0.78, 0.78, 0.77, 0.42, 0.18],
346+
[0.82, 0.93, 0.78, 0.00, 0.00, 0.78, 0.30, 0.15],
347+
[0.68, 0.85, 0.78, 0.00, 0.00, 0.78, 0.13, 0.06],
348+
[0.46, 0.68, 0.77, 0.78, 0.78, 0.13, 0.03, 0.01],
349+
[0.24, 0.39, 0.42, 0.30, 0.13, 0.03, 0.00, 0.00],
350+
[0.00, 0.10, 0.18, 0.15, 0.06, 0.01, 0.00, 0.00]],
351+
352+
[[0.90, 0.79, 0.81, 0.76, 0.58, 0.35, 0.17, 0.00],
353+
[0.79, 0.88, 0.92, 0.88, 0.73, 0.50, 0.24, 0.05],
354+
[0.81, 0.92, 1.00, 0.50, 0.50, 0.53, 0.22, 0.09],
355+
[0.76, 0.88, 0.50, 0.00, 0.00, 0.50, 0.12, 0.05],
356+
[0.58, 0.73, 0.50, 0.00, 0.00, 0.50, 0.03, 0.01],
357+
[0.35, 0.50, 0.53, 0.50, 0.50, 0.02, 0.00, 0.00],
358+
[0.17, 0.24, 0.22, 0.12, 0.03, 0.00, 0.00, 0.00],
359+
[0.00, 0.05, 0.09, 0.05, 0.01, 0.00, 0.00, 0.00]],
352360

353361
[[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
354362
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
@@ -358,6 +366,7 @@ def test_light_source_masked_shading():
358366
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
359367
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
360368
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00]]]).T
369+
361370
assert_array_almost_equal(rgb, expect, decimal=2)
362371

363372

0 commit comments

Comments
 (0)