Skip to content

Closes 4425 (adds axis handling to mean, var, std) - #4442

Merged
ajpotts merged 1 commit into
Bears-R-Us:masterfrom
drculhane:Closes-4425
Jun 2, 2025
Merged

ajpotts merged 1 commit into
Bears-R-Us:masterfrom
drculhane:Closes-4425

Conversation

@drculhane

@drculhane drculhane commented May 22, 2025 •

Copy link
Copy Markdown
Contributor

Closes #4425 and #4443

Addendum to addendum

Rebased to current master to eliminate conflicts.

Addendum

mean is now in common_reductions

std and var are now in common_stats_reductions. Another reduction function was needed because std and var have the ddof parameter, which the other functions don't have.

Chapel-side, the functions mean and meanReduce have been renamed to meanAll and mean.
The functions variance and varReduce have been renamed to varAll and varReduce ("var" is a reserved chapel keyword).
The functions std and stdReduce have been renamed to stdAll and stdReduce (because they have to use the same naming convention as var, since they're in the same reduction group).

Other python functions that call mean, var and std have had their interfaces updated to the names above.


This adds axis handling (including negative axis handling) to ak.mean, ak.var and ak.std in numpy/pdarrayclass.py, but not (yet) to similar functions in segarray, groupby and array_api.

Notes about the code:

ak.mean, ak.var and ak.std now allow axis and keepdims arguments. They all call utility functions to parse the axis, and to validate negative axes. If no axis slicing is required, they operate as they always did (calling the server functions mean, var, or std). If there is axis slicing, they call meanReduce, varReduce or stdReduce. Note that these Reduce functions were already there server-side, but weren't being used by ak.mean, ak.var, and ak.std.

Worth noting: the three python functions (mean, var, std) are almost identical. The only differences are (1) the chapel functions they call, and (2) mean doesn't have a ddof arg, while var and std do.

Also worth noting: timeclass.py includes a std function which calls ak.std, so I had to rewrite the interface to be compatible with ak.std.

Also also worth noting: similar to python side, the functions meanReduce, varReduce and stdReduce are almost identical.

I added a call to validateNegativeAxes to meanReduce, varReduce and stdReduce (even though we're now doing the check python-side) as we discussed.

The docstrings for all three functions have been updated to include descriptions of the added parameters and behavior, and examples with the axis arguments.

Unit tests have also been added that use the axis arguments.

@drculhane drculhane changed the title Ready for initial review Closes 4425 (adds axis handling to mean, var, std) May 22, 2025
@drculhane
drculhane marked this pull request as ready for review May 22, 2025 19:14

@ajpotts ajpotts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great! Thank you for taking care of this!

However, I think we should refactor to match the other reduction functions by calling the _common_reduction function.

Comment thread arkouda/numpy/pdarrayclass.py Resolved
Comment thread arkouda/numpy/pdarrayclass.py Resolved
Comment thread arkouda/numpy/pdarrayclass.py Resolved
@drculhane
drculhane force-pushed the Closes-4425 branch 5 times, most recently from 6310d74 to 4bd39e5 Compare May 28, 2025 11:12

@1RyanK 1RyanK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

@ajpotts
ajpotts added this pull request to the merge queue Jun 2, 2025
Merged via the queue into Bears-R-Us:master with commit 91d85a0 Jun 2, 2025
@drculhane
drculhane deleted the Closes-4425 branch June 3, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bring consistency to axis handling in mean, std, and var

3 participants