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

Skip to content

Data types not preserved in categoricals #9350

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
story645 opened this issue Oct 10, 2017 · 5 comments
Closed

Data types not preserved in categoricals #9350

story645 opened this issue Oct 10, 2017 · 5 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: categorical
Milestone

Comments

@story645
Copy link
Member

story645 commented Oct 10, 2017

@anntzer pointed out on #9340 that the behavior for plt.plot([23, "23"]) should be two data points with identical labels. Currently it collapses them into one value:
index

@story645 story645 added topic: categorical Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Oct 10, 2017
@anntzer anntzer added this to the 2.1.1 (next bug fix release) milestone Oct 10, 2017
@tacaswell
Copy link
Member

I am not super concerned about this, it is string catagoricals.

@efiring
Copy link
Member

efiring commented Oct 10, 2017

Which brings us back to @anntzer's earlier suggestion that we should raise an error instead of accepting this nonsensical input.

@anntzer
Copy link
Contributor

anntzer commented Oct 20, 2017

As an additional point where allowing uncontrolled mixing of strings and numbers can be puzzling:

fill_between([0, 1, 2], [2, 3, 2])

great, let's plot this in red

fill_between([0, 1, 2], [2, 3, 2], "r")

(saved on the same figure to save some room)
figure_1

Ah, that's because the second parameter is "y2" (so I needed to write color="r") and "r" got converted to "0" by the categorical converter... (I would say once an axes has used the scalar (passthrough) converter it should disable the categorical converter, just as the categorical converter should not pass scalars through.)

I knew exactly the issue with categoricals, and that behavior still led to a bit a head scratching...

@story645
Copy link
Member Author

story645 commented Oct 20, 2017

I agree that's a bug, but the issue seems to be that the second positional parameter is ambiguous. Like it's technically doing the correct thing, given that this works the exact same way:

plt.fill_between([0, 1, 2], [2, 3, 2], 0)

What I mean is

plt.fill_between(['a', 'b', 'c'], ['e', 'f', 'g'], 'r')

Errors out spectacularly because it tries to do a lookup on 'r' against the existing mapping and doesn't see it as a new value:

~/projects/matplotlib/lib/matplotlib/category.py in convert(value, unit, axis)
     47 
     48         if isinstance(value, six.string_types):
---> 49             return vmap[value]
     50 
     51         str_value = shim_array(value)

KeyError: 'r'

Also, it's not hitting the update and instead going straight to the convert, which is why this isn't working either:

ETA: Ok, I think your point is that once I've set the yaxis to being scaler, it should have a flag of sorts that all other values passed to it need to use the same units? That seems reasonable/I agree.

@tacaswell
Copy link
Member

Closed by #9783

Still some broken edge cases (which we have tests for now).

@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: categorical
Projects
None yet
Development

No branches or pull requests

5 participants