Skip to content

BUG: Fix np.testing utils failing for masked scalar vs. scalar (#29317) #29318

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 4 commits into from
Jul 13, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MNT: Improve comments on assert_array_compare nan/inf handling logic
- Use same language as elsewhere below to explain `!= True` used to
  handle np.ma.masked
- Clarify committed to support standard MaskedArrays
- Restore note lost in 7315145 comment changes about how the
  np.bool casts towards the end of the function handle np.ma.masked,
  and expand further.
  • Loading branch information
danra committed Jul 10, 2025
commit 32ba514866d26dd4d27f60ce09d376af643843a8
9 changes: 6 additions & 3 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,15 @@ def func_assert_same_pos(x, y, func=isnan, hasval='nan'):
y_id = func(y)
# We include work-arounds here to handle three types of slightly
# pathological ndarray subclasses:
# (1) all() on `masked` array scalars can return masked arrays, so we
# use != True
# (1) all() on fully masked arrays returns np.ma.masked, so we use != True
# (np.ma.masked != True evaluates as np.ma.masked, which is falsy).
# (2) __eq__ on some ndarray subclasses returns Python booleans
# instead of element-wise comparisons, so we cast to np.bool() in
# that case (or in case __eq__ returns some other value with no
# all() method).
# (3) subclasses with bare-bones __array_function__ implementations may
# not implement np.all(), so favor using the .all() method
# We are not committed to supporting such subclasses, but it's nice to
# We are not committed to supporting cases (2) and (3), but it's nice to
# support them if possible.
result = x_id == y_id
if not hasattr(result, "all") or not callable(result.all):
Expand All @@ -794,6 +794,9 @@ def func_assert_same_pos(x, y, func=isnan, hasval='nan'):
raise AssertionError(msg)
# If there is a scalar, then here we know the array has the same
# flag as it everywhere, so we should return the scalar flag.
# np.ma.masked is also handled and converted to np.False_ (even if the other
# array has nans/infs etc.; that's OK given the handling later of fully-masked
# results).
if isinstance(x_id, bool) or x_id.ndim == 0:
return np.bool(x_id)
elif isinstance(y_id, bool) or y_id.ndim == 0:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy