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

Skip to content

Commit 988b328

Browse files
committed
add tests/test_colors.py with test for issue #1005
1 parent a99651e commit 988b328

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ def tk_window_focus():
10081008
'matplotlib.tests.test_basic',
10091009
'matplotlib.tests.test_cbook',
10101010
'matplotlib.tests.test_colorbar',
1011+
'matplotlib.tests.test_colors',
10111012
'matplotlib.tests.test_dates',
10121013
'matplotlib.tests.test_delaunay',
10131014
'matplotlib.tests.test_figure',

lib/matplotlib/tests/test_colors.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Tests for the colors module.
3+
"""
4+
5+
from __future__ import print_function
6+
import numpy as np
7+
from numpy.testing.utils import assert_array_equal
8+
import matplotlib.colors as mcolors
9+
import matplotlib.cm as cm
10+
11+
def test_colormap_endian():
12+
"""
13+
Github issue #1005: a bug in putmask caused erroneous
14+
mapping of 1.0 when input from a non-native-byteorder
15+
array.
16+
"""
17+
cmap = cm.get_cmap("jet")
18+
# Test under, over, and invalid along with values 0 and 1.
19+
a = [-0.5, 0, 0.5, 1, 1.5, np.nan]
20+
for dt in ["f2", "f4", "f8"]:
21+
anative = np.array(a, dtype=dt)
22+
aforeign = anative.byteswap().newbyteorder()
23+
print(anative.dtype.isnative, aforeign.dtype.isnative)
24+
assert_array_equal(cmap(anative), cmap(aforeign))
25+
26+

0 commit comments

Comments
 (0)