From dfafe4218b0084b2389b14e955c3e619b89aa88c Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 9 Oct 2017 18:21:57 -0400 Subject: [PATCH 1/4] bugfix for #9336 and test for integer overwrite --- lib/matplotlib/category.py | 7 ++++--- lib/matplotlib/tests/test_category.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/category.py b/lib/matplotlib/category.py index d043c5b154a5..7b86f110874b 100644 --- a/lib/matplotlib/category.py +++ b/lib/matplotlib/category.py @@ -45,12 +45,13 @@ def convert(value, unit, axis): 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 6e5c43d76fb9..57e2c44dbf6c 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -71,8 +71,10 @@ 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])] + + ids = ["unicode", "single", "basic", "mixed", "integer"] @pytest.fixture(autouse=True) def mock_axis(self, request): From b0af911a3fcef38650561c12c6ecca8a382a2b1a Mon Sep 17 00:00:00 2001 From: hannah Date: Tue, 10 Oct 2017 12:53:53 -0400 Subject: [PATCH 2/4] value pass through --- lib/matplotlib/category.py | 4 ++++ lib/matplotlib/tests/test_category.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/category.py b/lib/matplotlib/category.py index 7b86f110874b..01f6e971a8dd 100644 --- a/lib/matplotlib/category.py +++ b/lib/matplotlib/category.py @@ -40,12 +40,16 @@ def convert(value, unit, axis): """Uses axis.unit_data map to encode data as floats """ + 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] str_value = shim_array(value) + mapped_value = str_value.copy() for lab, loc in vmap.items(): diff --git a/lib/matplotlib/tests/test_category.py b/lib/matplotlib/tests/test_category.py index 57e2c44dbf6c..db04c909c8e5 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -72,9 +72,10 @@ class TestStrCategoryConverter(object): [('nan', -1), ('3.14', 0), ('A', 1), ('B', 2), ('-inf', 100), ('inf', 200)], [1, 1, -1, 2, 100, 0, 200]), - (["!", "0"], [("!", 0), ("0", 1)], [0, 1])] + (["!", "0"], [("!", 0), ("0", 1)], [0, 1]), + (0.0, [(0.0, 0.0)], 0.0)] - ids = ["unicode", "single", "basic", "mixed", "integer"] + ids = ["unicode", "single", "basic", "mixed", "integer str", "number"] @pytest.fixture(autouse=True) def mock_axis(self, request): From 29c359652c68ee58cd50c427c95e3d136699b191 Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 9 Oct 2017 18:21:57 -0400 Subject: [PATCH 3/4] bugfix for #9336 and test for integer overwrite --- lib/matplotlib/category.py | 7 ++++--- lib/matplotlib/tests/test_category.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/category.py b/lib/matplotlib/category.py index d2754d32fd3a..7421e141c750 100644 --- a/lib/matplotlib/category.py +++ b/lib/matplotlib/category.py @@ -51,12 +51,13 @@ def convert(value, unit, axis): 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..1632d480fa11 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -71,8 +71,10 @@ 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])] + + ids = ["unicode", "single", "basic", "mixed", "integer"] @pytest.fixture(autouse=True) def mock_axis(self, request): From 48f5e1fd9ce9cd8f416119890f38599030ad540f Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 13 Nov 2017 16:18:01 -0500 Subject: [PATCH 4/4] working on redoing category w/ mixed type semantics --- lib/matplotlib/category.py | 5 +++++ lib/matplotlib/tests/test_category.py | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/category.py b/lib/matplotlib/category.py index 7421e141c750..490941b8f564 100644 --- a/lib/matplotlib/category.py +++ b/lib/matplotlib/category.py @@ -46,12 +46,17 @@ def convert(value, unit, axis): for val in value: if isinstance(val, six.string_types): axis.unit_data.update(val) + + 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] str_value = shim_array(value) + mapped_value = str_value.copy() for lab, loc in vmap.items(): diff --git a/lib/matplotlib/tests/test_category.py b/lib/matplotlib/tests/test_category.py index 1632d480fa11..00aaf305823b 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -72,9 +72,10 @@ class TestStrCategoryConverter(object): [('nan', -1), ('3.14', 0), ('A', 1), ('B', 2), ('-inf', 100), ('inf', 200)], [1, 1, -1, 2, 100, 0, 200]), - (["!", "0"], [("!", 0), ("0", 1)], [0, 1])] + (["!", "0"], [("!", 0), ("0", 1)], [0, 1]), + (0.0, [(0.0, 0.0)], 0.0)] - ids = ["unicode", "single", "basic", "mixed", "integer"] + ids = ["unicode", "single", "basic", "mixed", "integer str", "number"] @pytest.fixture(autouse=True) def mock_axis(self, request):