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

Skip to content

BUG: fix ma.minimum.reduce with axis keyword #21993

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

Merged
merged 2 commits into from
Jul 17, 2022
Merged

Conversation

rcomer
Copy link
Contributor

@rcomer rcomer commented Jul 16, 2022

Fixes the problem reported at #21977 (comment).

The reduce method here effectively calls itself with an unmasked MaskedArray (mask=nomask) and then expects either a MaskedArray or a scalar. This change ensures that an ordinary ndarray is converted to a MaskedArray, following the pattern already used in mean and var in this module.

When t was an ndarray, we called elif m on a boolean array, triggering the "ambiguous truth value" error.

numpy/numpy/ma/core.py

Lines 6883 to 6886 in bdec321

if hasattr(t, '_mask'):
t._mask = m
elif m:
t = masked

rcomer added 2 commits July 16, 2022 15:00
Fixes the problem reported at
numpy#21977 (comment)

The reduce method here effectively calls itself with an unmasked
MaskedArray (mask=nomask) and then expects either a MaskedArray or
a scalar.  This change ensures that an ordinary ndarray is
converted to a MaskedArray, following the pattern already used in
mean and var in this module.
Copy link
Member

@HaoZeke HaoZeke left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mattip mattip merged commit a87031f into numpy:main Jul 17, 2022
@mattip
Copy link
Member

mattip commented Jul 17, 2022

Thanks @rcomer

@rcomer
Copy link
Contributor Author

rcomer commented Jul 17, 2022

Thanks @HaoZeke, @mattip.

@InessaPawson
Copy link
Member

Hi-five on merging your first pull request to NumPy, @rcomer! We hope you stick around! Your choices aren’t limited to programming – you can review pull requests, help us stay on top of new and old issues, develop educational material, work on our website, add or improve graphic design, create marketing materials, translate website content, write grant proposals, and help with other fundraising initiatives. For more info, check out: https://numpy.org/contribute
Also, consider joining our mailing list. This is a great way to connect with other cool people in our community and be part of important conversations that affect the development of NumPy: https://mail.python.org/mailman/listinfo/numpy-discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

4 participants