-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Use masked stack to preserve mask info #24732
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
Conversation
Can you please add a test (like just copy the one in #24545)? (This seems to be the correct fix, although my knowledge of masked is very limited...) |
Nice detective work @chahak13! Could you add a test that would have failed without this change? Maybe adapt the example from #24545 into an image test. [Edit: cross-post with @oscargus, but it is good to see we agreed!] |
Btw, the same thing cannot happen here as well? matplotlib/lib/matplotlib/collections.py Line 322 in cc85fb6
But maybe paths cannot have units or masked arrays to start with? |
It may be that this is actually better solved in matplotlib/lib/matplotlib/collections.py Lines 548 to 550 in cc85fb6
which would then remove the need for an additional unit conversion etc. Anyway, probably better to get this in and then spend some effort trying to make it more unified. The risk is that it will take quite a bit of time to untangle everything... |
@oscargus good point. This might actually be a more deep-rooted issue. I checked |
I've added a test and baseline images for this for now. This should resolve the current issue but I'll try to dig into the usage of masked data later. Let me know if there's something missing! |
Thanks! Maybe, for the sake of it, add a (It may be enough to only have one of the format, e.g., png, but that would require a rebase with force push as the cleanliness test will become unhappy otherwise.) |
Oh, and if there is a way to actually get a masked Path with units to test with that would be great, but shouldn't be a show stopper for now. |
@oscargus @rcomer, need advice. I was working on the TLDR: matplotlib/lib/matplotlib/axis.py Lines 1731 to 1740 in cc85fb6
The reason the fix that I made worked for this case is that the mask was on a numeric field. For all the non-number types, |
I'd say skip the equal test then for now. It may be a deep rabbit hole... I'll add a comment to #24733 pointing this out. Probably the right thing is to support masked arrays in |
Understood, thanks. I'll resolve the 2 comments on the review then. |
6c59932
to
9001a20
Compare
That should do it. Let me know if there's anything needed! |
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.
Thanks @chahak13, this looks good to me (assuming CI passes, but I can't see a reason it wouldn't).
Thanks! FYI, it wasn't that tricky to get masked dates to pass: #24734 But we can add the image equal test when digging into the other aspects later. |
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.
Agreed! Looks good! Anyone can merge on green.
Yes, it was pretty straight forward! I had the fix on my local machine but just wasn't sure if we wanted to include that in this or would that be out of scope for this particular PR. Thanks though! |
Ahh, sorry about that then. Just didn't want you to go down a potential rabbit hole by encouraging it... |
…732-on-v3.6.x Backport PR #24732 on branch v3.6.x (Use masked stack to preserve mask info)
PR Summary
As pointed out in #24545 ,
scatter
was not masking datetime correctly. This issue would be true for any data with units because of the following linesmatplotlib/lib/matplotlib/collections.py
Lines 323 to 325 in cc85fb6
Whenever
self.have_units()
wasTrue
, it would usenp.column_stack
instead ofnp.ma.column_stack
which would lead to the loss of mask information. Changing that to the masked version resolves #24545 .PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst