Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Fix for plt.plot() does not support structured arrays as data= kwarg#10810
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
707ca97 to73101a2Compare
jklymak left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This works as advertised, and I don't see that its breaking anything...
efiring left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good.
efiring commentedMar 16, 2018
@tacaswell, do you want to stick one of the version 2 milestones on this? It is addressing a bug milestoned for 2.2, and it looks like a clean and simple fix. |
tacaswell commentedMar 16, 2018
Inclined to not backport, this never worked (so not fixing a regression), is not a failure to import / segfault, and the user has a clear work around (just don't use the data kwarg with structured arrays). The issue here is that structured arrays support Does this change how things fail if you pass in keys that are not a coloror in the container? |
efiring commentedMar 16, 2018
@tacaswell, thank you, I had not looked into the situation in enough detail. It sounds like the real solution for fully supporting structured arrays would be to make |
jklymak left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
... as per comments bu@tacaswell, this looks to need more thought. However, if it breaks data kwarg handling and passes our current tests, it means we are missing tests on this functionality.
tacaswell commentedMar 16, 2018
Thanks for working on this@zhangeugenia . Despite my seemingly negative comments, I think this is definitely going in the right direction and appreciate your work! |
zhangeugenia commentedMar 18, 2018
Hello! Thank you all for your time and feedback, I greatly appretiate it (especially since plot() is a very important function)! As@tacaswell mentioned, this PR does indeed change the behaviour of Out of the two methods that@efiring proposed to support structured arrays, the latter (to check the type of data, and invoke I do have a question regarding testing though - once the support for structured arrays has been implemented, if I were to add tests to test Thank you! |
I'm not filly parsing the issue here, so will drop out of review. However, I can look into it if core devs too busy. Just ping issue again
efiring commentedMar 18, 2018
@zhangeugenia I think I would putdirect tests of Going the subclass route might not be a good idea--I suspect it would be overkill, and it is probably much trickier than one might expect. Is there likely to be any other place where it would help enough to justify the fuss? All you need for option 1 is something like ifnot (args[1]indataorhasattr(data,'dtype')andargs[1]indata.dtype.names): To be even safer, in case something comes through with a 'dtype' that is not a standard numpy dtype, you could insert |
efiring commentedMar 18, 2018
Additional note: ndarrays, structured or not, do have acontains method, but it doesn't do what we need here. |
tacaswell commentedMar 18, 2018
I like@efiring 's suggestion. I am hesitant to add direct tests of |
zhangeugenia commentedMar 18, 2018
Thank you for your guidance! Indeed, a wrapper class would be a lot of work, I just thought it would reduce issues with using I will take@efiring 's suggestion and make the needed changes to |
fb20640 to73101a2Comparezhangeugenia commentedMar 23, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Updated to use@efiring 's suggestion! A check for |
tacaswell commentedMar 23, 2018
Looks good to me! |
efiring commentedMar 23, 2018
Thank you,@zhangeugenia! |
| # this can be two cases: x,y or y,c | ||
| ifnotargs[1]indata: | ||
| if (notargs[1]indataand | ||
| not (hasattr(data,'dtype')and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This check is correct, but a bit hard to read. I would just try ... except. The cleanest way would be a little helper function:
def _has_name(data, name): try: return name in data or name in data.dtype.names except (AttributeError, TypeError): return Falseand then
if _has_name(data, args[1]): return ["y", "c"]tacaswell commentedMar 28, 2018
Thanks@zhangeugenia and congratulations on what is (I think?) your first merged Matplotlib PR 🎉 Hopefully we will hear from you again! |
PR Summary
Fix for issue#8818 - plot() is now be able to plot structured arrays passed in as data=... kwarg without incorrectly interpreting the data as a format string.
A small simple test case is included with this PR to check that plotting a structured array will not cause and exception (without the use of image comparison since it felt unneeded).
If any changes/modifications are needed, please let me know. Thank you!