diff --git a/lib/matplotlib/category.py b/lib/matplotlib/category.py index d2754d32fd3a..a71d63239abe 100644 --- a/lib/matplotlib/category.py +++ b/lib/matplotlib/category.py @@ -40,23 +40,32 @@ def convert(value, unit, axis): """Uses axis.unit_data map to encode data as floats """ +<<<<<<< HEAD +======= value = np.atleast_1d(value) # try and update from here.... if hasattr(axis.unit_data, 'update'): for val in value: if isinstance(val, six.string_types): axis.unit_data.update(val) + +>>>>>>> temp-branch + if units.ConversionInterface.is_numlike(value): + return value + vmap = dict(zip(axis.unit_data.seq, axis.unit_data.locs)) if isinstance(value, six.string_types): return vmap[value] - vals = shim_array(value) + str_value = shim_array(value) + + mapped_value = str_value.copy() for lab, loc in vmap.items(): - vals[vals == lab] = loc + mapped_value[str_value == lab] = loc - return vals.astype('float') + return mapped_value.astype("float") @staticmethod def axisinfo(unit, axis): diff --git a/lib/matplotlib/tests/test_category.py b/lib/matplotlib/tests/test_category.py index 7156dc59933c..00aaf305823b 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -71,8 +71,11 @@ class TestStrCategoryConverter(object): (['A', 'A', np.nan, 'B', -np.inf, 3.14, np.inf], [('nan', -1), ('3.14', 0), ('A', 1), ('B', 2), ('-inf', 100), ('inf', 200)], - [1, 1, -1, 2, 100, 0, 200])] - ids = ["unicode", "single", "basic", "mixed"] + [1, 1, -1, 2, 100, 0, 200]), + (["!", "0"], [("!", 0), ("0", 1)], [0, 1]), + (0.0, [(0.0, 0.0)], 0.0)] + + ids = ["unicode", "single", "basic", "mixed", "integer str", "number"] @pytest.fixture(autouse=True) def mock_axis(self, request):