Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: ensure that errorbar does not error on masked negative errors.#29897

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

Merged
QuLogic merged 3 commits intomatplotlib:mainfrommhvk:allow_masked_negative_errors
Apr 16, 2025

Conversation

mhvk
Copy link
Contributor

@mhvkmhvk commentedApr 10, 2025
edited
Loading

errorbar checks that errors are not negative, but a bit convolutedly, in order to avoid triggering on nan. Unfortunately, the work-around for nan means that possible masks get discarded, and hence passing in a masked error array that has a negative but masked value leads to an exception. This PR solves that by simply combining the test for
negative values with the indirect isnan test (err == err), so that if a masked array is passed, the test values are masked and ignored in the check.

As a bonus, this also means that astropy'sMasked arrays can now be used -- those refuse to write output of tests to unmasked values since that would discard the mask (which is indeed the underlying problem here) -- see
astropy/astropy#17996

p.s. I checked that the test case that I added fails on current main. The test case is based on the one fornan right above - let me know if this is an OK location for it.

EDIT: updated to simplify the check without using any storing of outputs. This means we can also continue to use astropy's Quantity for error bars (and just shows how damn careful one has to be, sigh).

EDIT 2: second commit prevents any comparison ofnan < nan, which causesRuntimeError that I did not see locally.

PR checklist

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@mhvkmhvkforce-pushed theallow_masked_negative_errors branch fromc22cac0 toae1edf8CompareApril 10, 2025 16:23
errorbar checks that errors are not negative, but a bit convolutedly,in order to avoid triggering on nan. Unfortunately, the work-aroundfor nan means that possible masks get discarded, and hence passing ina masked error array that has a negative but masked value leads toan exception. This PR solves that by simply combining the test fornegative values with the indirect isnan test (err == err), so thatif a masked array is passed, the test values are masked and ignoredin the check.As a bonus, this also means that astropy's ``Masked`` arrays can nowbe used -- those refuse to write output of tests to unmasked valuessince that would discard the mask (which is indeed the underlyingproblem here).
@tacaswell
Copy link
Member

The underlying (underlying) problem is thatnp.where does not respect the mask and__getitem__ does?

@mhvk
Copy link
ContributorAuthor

The underlying (underlying) problem is thatnp.where does not respect the mask and__getitem__ does?

No, the problem is that when writing directly to a regular array, as happened innp.less(err, -err, out=res) (whereres was a regular array created withnp.zeros), the mask gets dropped (more specifically,np.less(err, -err) would normally return a masked boolean array, with the mask a copy of the mask oferr, but writing that tores drops the mask).

p.s. What was a surprise is thatnp.less raises aRuntimeWarning fornp.nan unless that particular element is not included inwhere -- a surprise mostly because I know from my ufunc work that generally thewhere argument does not actually prevent the function to be done on the arguments, it just avoids the result being written back. But perhaps it is different for the comparisons -nan are of course notorious and there is a lot of extra code to work around them... Anyway, unrelated to the issue at hand!

@mhvk
Copy link
ContributorAuthor

Actually, I guess I misread your question: yes, it is also true that thewhere argument ignores the mask on the output oferr == err.

@mhvkmhvkforce-pushed theallow_masked_negative_errors branch from5c42d71 toebeb83aCompareApril 13, 2025 12:18
@mhvk
Copy link
ContributorAuthor

@dstansby - comments addressed (I hope).

Copy link
Member

@dstansbydstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks!

@QuLogicQuLogic merged commite1887b8 intomatplotlib:mainApr 16, 2025
39 of 41 checks passed
@QuLogic
Copy link
Member

Thanks@mhvk! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

bsipocz reacted with hooray emojibsipocz reacted with heart emoji

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestApr 16, 2025
@mhvkmhvk deleted the allow_masked_negative_errors branchApril 16, 2025 11:14
@bsipocz
Copy link
Contributor

Thanks@mhvk for fixing this!

QuLogic added a commit that referenced this pull requestApr 17, 2025
…897-on-v3.10.xBackport PR#29897 on branch v3.10.x (BUG: ensure that errorbar does not error on masked negative errors.)
@ksundenksunden mentioned this pull requestMay 9, 2025
5 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@tacaswelltacaswelltacaswell approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.10.3
Development

Successfully merging this pull request may close these issues.

5 participants
@mhvk@tacaswell@QuLogic@bsipocz@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp