Skip to content

Commit 29c3596

Browse files
committed
bugfix for matplotlib#9336 and test for integer overwrite
1 parent c508c35 commit 29c3596

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎lib/matplotlib/category.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ def convert(value, unit, axis):
5151
if isinstance(value, six.string_types):
5252
return vmap[value]
5353

54-
vals = shim_array(value)
54+
str_value = shim_array(value)
55+
mapped_value = str_value.copy()
5556

5657
for lab, loc in vmap.items():
57-
vals[vals == lab] = loc
58+
mapped_value[str_value == lab] = loc
5859

59-
return vals.astype('float')
60+
return mapped_value.astype("float")
6061

6162
@staticmethod
6263
def axisinfo(unit, axis):

‎lib/matplotlib/tests/test_category.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ class TestStrCategoryConverter(object):
7171
(['A', 'A', np.nan, 'B', -np.inf, 3.14, np.inf],
7272
[('nan', -1), ('3.14', 0), ('A', 1), ('B', 2),
7373
('-inf', 100), ('inf', 200)],
74-
[1, 1, -1, 2, 100, 0, 200])]
75-
ids = ["unicode", "single", "basic", "mixed"]
74+
[1, 1, -1, 2, 100, 0, 200]),
75+
(["!", "0"], [("!", 0), ("0", 1)], [0, 1])]
76+
77+
ids = ["unicode", "single", "basic", "mixed", "integer"]
7678

7779
@pytest.fixture(autouse=True)
7880
def mock_axis(self, request):

0 commit comments

Comments
 (0)