BUG: Pass DType class np.average to support weights argument for user-dtypes#31575
Open
SwayamInSync wants to merge 1 commit into
Open
BUG: Pass DType class np.average to support weights argument for user-dtypes#31575SwayamInSync wants to merge 1 commit into
np.average to support weights argument for user-dtypes#31575SwayamInSync wants to merge 1 commit into
Conversation
np.average to support weights argument for user-dtypesnp.average to support weights argument for user-dtypes
mhvk
reviewed
Jun 6, 2026
|
|
||
| a = np.array([1, 2, 3, 4], dtype=qd) | ||
| w = np.array([4, 3, 2, 1], dtype=qd) | ||
| assert float(np.average(a)) == 2.5 |
Contributor
There was a problem hiding this comment.
I think one should test that the returned array has the right data type, with, e.g.,
assert_array_equal(np.average(a), np.array(2.5, dtype=qd), strict=True)
Note that it might also be good to make sure the precision is in fact kept, e.g., by writing
a = np.array([1, 2, 3, 4], dtype=qd) + np.array(1e-20, dtype=dq)
w = np.array([4, 3, 2, 1], dtype=qd) - np.array(1e-21, dtype=dq)
(and obviously adjusting the result accordingly)
Member
|
This needs the quaddtype test helper from gh-31574. That looks like the reason for the CI failures here (it's very cryptic, but quaddtype had some bugs that caused cryptic crazy issues :)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
Same fix as #31447
Discovered at numpy/numpy-quaddtype#106
AI Disclosure
None