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

Skip to content

bugfix/test for #9336 integer overwrite in categorical #9340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/matplotlib/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions lib/matplotlib/tests/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down