-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Handle np.average with different shape weights and input array and returning sum of weights
#19055
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
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
Thanks! Please add a bugfix change log. https://github.com/astropy/astropy/blob/main/docs/changes/README.rst |
mhvk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for both reporting the original issue and making a PR with the fix!
See my few in-line comments. Also, as @pllim noted, would be good to have a changelog fragment.
…eturning sum of weights.
3064dca to
47d807c
Compare
|
Um, merging main was a mistake - rebased and force-pushed instead. Sorry for any confusion! |
|
|
||
| a = _as_quantity(a) | ||
| a_value, a_unit = a.value, a.unit | ||
| weights = _as_quantity(weights) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This raises an error for weights=None, no?
Hmm, just checked, that indeed errors. There should have been a test for that... Let me push the fix directly to your branch.
mhvk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kyleaoman! Approving with my small modification, and will set to merge.
…eights and input array and returning sum of weights
…055-on-v7.2.x Backport PR #19055 on branch v7.2.x (Handle `np.average` with different shape weights and input array and returning sum of weights)
Description
This pull request is to address an issue where the
np.averagefunction strips the units from the optionally-returned sum of weights. A complete description and instructions to reproduce are at #19054The fix is simple: I've just moved
np.averageout ofSUBCLASS_SAFE_FUNCTIONSand intoFUNCTION_HELPERSand written a suitable helper. I've also added a regression test.Fixes #19054