Skip to content

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented Dec 26, 2025

Over at astropy, it was noticed that if one passes in a Quantity weight to np.average, and asks for the summed weight to be returned, then the unit can be lost if the shapes of the weights and input array do not match (see astropy/astropy#19054). This is because of a missing subok=True in a final broadcast -- which this PR fixes (how I wish I had insisted more that that would be default for subok when it was introduced...).

ra, rw = np.average(a, weights=w, returned=True)
assert_equal(type(ra), subclass)
assert_equal(type(rw), subclass)
# Even if it needs to be broadcast.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test fails without the subok=True argument.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Dec 26, 2025
@charris charris added this to the 2.4.1 Release milestone Dec 26, 2025
@charris
Copy link
Member

charris commented Dec 26, 2025

Thanks Marten.

@mhvk
Copy link
Contributor Author

mhvk commented Dec 26, 2025

That's quick! Thanks, Chuck.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants