docs: document named-axis support for axis in high-level operations#3823
docs: document named-axis support for axis in high-level operations#3823ikrommyd merged 26 commits intoscikit-hep:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
|
The documentation preview is ready to be viewed at http://preview.awkward-array.org.s3-website.us-east-1.amazonaws.com/PR3823 |
|
cc @pfackeldey since you are much better at typing than me. I don’t know if this is the best though because AxisName already includes int and None right? |
ianna
left a comment
There was a problem hiding this comment.
@X0708a - Thanks! It's a great start and IMHO the task of axis clarification is much bigger that adding it to one function.
Also, to make the reference manual actually useful for someone encountering AxisName, AxisTuple, or AxisMapping terms, they should linked to some explanation (btw, does it exist in docs?). The type aliases should be explained in terms of the functional role of them in the metadata.
I think, I would prefer consistency in the documentation and have one PR that clarifies axis in all high level functions that use it. It would be a much bigger job though :-)
|
FYI, named axes can only be strings. See awkward/src/awkward/_namedaxis.py Lines 137 to 163 in 680ab6e Therefore, I think for the tine being "int or None or string" is fine for the docstrings (and one can add a small oneliner that string is only in the case the axes are named). Something like |
|
Updated user-facing typing and docstrings across high-level reducers to |
|
There is no such commit that I see. |
|
Thanks for flagging this - the updates were on a different branch. |
There was a problem hiding this comment.
You have introduced type hints in places where we don't have type hints and for only one parameter. You should only change docstrings here and not for just reducers but for all highlevel functions that have an axis parameter. Your docstring addition should probably point the users to the named axis user guide. No type hints should be introduced in places where there aren't any.
|
I’ve rebased onto the latest state of the branch and updated axis docstrings |
|
I believe all requested changes have been addressed. Please let me know if there’s anything else I should adjust. |
|
The current changes are definitely not for all highlevel functions included under diff --git a/src/awkward/operations/ak_moment.py b/src/awkward/operations/ak_moment.py
index e8433a02..b9a16fe7 100644
--- a/src/awkward/operations/ak_moment.py
+++ b/src/awkward/operations/ak_moment.py
@@ -44,11 +44,15 @@ def moment(
weight. Weighting values equally is the same as no weights;
weighting some values higher increases the significance of those
values. Weights can be zero or negative.
- axis (None or int): If None, combine all values from the array into
+ axis (None or int or str): If None, combine all values from the array into
a single scalar result; if an int, group by that axis: `0` is the
outermost, `1` is the first level of nested lists, etc., and
negative `axis` counts from the innermost: `-1` is the innermost,
- `-2` is the next level up, etc.
+ `-2` is the next level up, etc. If a str, it is interpreted as
+ the name of the axis which maps to an int if named axes are present.
+ Named axes are attached to an array using
+ #ak.with_named_axis and removed with #ak.without_named_axis; also
+ see the [Named axes user guide](../../user-guide/how-to-array-properties-named-axis.html).
keepdims (bool): If False, this function decreases the number of
dimensions by 1; if True, the output values are wrapped in a new
length-1 dimension so that the result of this operation may bebut it needs to be done for ALL highlevel functions similarly. |
|
Thanks for the concrete example, that’s very helpful. Understood — I’ll update the axis docstrings following this pattern (preserving |
|
I’ve now updated all high-level operations to consistently document named-axis support for axis, without removing existing docstring content, and added a link to the named-axis user guide. |
ianna
left a comment
There was a problem hiding this comment.
@X0708a - thank for addressing the comments! The axis doc seems out of place. Please remove it. Also- have you checked all other high level functions that take axis parameter? Btw, the pr title doesn’t correspond to its content anymore 😀
|
Thanks for the careful review and the ripgrep lists was very helpful. |
|
I only looked at the changed files now and I think you now have touched all highlevel functions. Please someone else double check me too. This is the complete ripgrep |
|
I noticed that you correctly did not change the |
ikrommyd
left a comment
There was a problem hiding this comment.
I think it should be good now? I don't see anything else in the docstrings but please someone else have a look too.
There was a problem hiding this comment.
Pull request overview
This PR updates documentation for the axis parameter across many high-level operations to document support for named axes (string axis names). The main change removes the problematic AxisName type annotation from ak.moment (which incorrectly allowed None as a hashable) and updates docstrings across 33 operation files to clarify that axis can be None, int, or str.
Changes:
- Removed
axis: AxisName = Nonetype annotation fromak.moment, replacing it withaxis=Noneto avoid type hint issues - Updated docstrings across 33 operations to document that
axisacceptsNone,int, orstrvalues - Added consistent documentation blocks explaining named axis support with links to the user guide
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/awkward/operations/ak_moment.py | Removed problematic AxisName type annotation from axis parameter; updated docstring |
| src/awkward/operations/ak_var.py | Updated axis docstring to document named-axis support for var and nanvar |
| src/awkward/operations/ak_unflatten.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_sum.py | Updated axis docstring to document named-axis support for sum and nansum |
| src/awkward/operations/ak_std.py | Updated axis docstring to document named-axis support for std and nanstd |
| src/awkward/operations/ak_sort.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_softmax.py | Updated and restructured axis docstring to document named-axis support |
| src/awkward/operations/ak_singletons.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_ptp.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_prod.py | Updated axis docstring to document named-axis support for prod and nanprod |
| src/awkward/operations/ak_pad_none.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_num.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_min.py | Updated axis docstring to document named-axis support for min and nanmin |
| src/awkward/operations/ak_merge_union_of_records.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_merge_option_of_records.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_mean.py | Updated axis docstring to document named-axis support for mean and nanmean |
| src/awkward/operations/ak_max.py | Updated axis docstring to document named-axis support for max and nanmax |
| src/awkward/operations/ak_local_index.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_linear_fit.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_is_none.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_flatten.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_firsts.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_fill_none.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_drop_none.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_covar.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_count_nonzero.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_count.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_corr.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_concatenate.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_combinations.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_cartesian.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_argsort.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_argmin.py | Updated axis docstring to document named-axis support for argmin and nanargmin |
| src/awkward/operations/ak_argmax.py | Updated axis docstring to document named-axis support for argmax and nanargmax |
| src/awkward/operations/ak_argcombinations.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_argcartesian.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_any.py | Updated axis docstring to document named-axis support |
| src/awkward/operations/ak_all.py | Updated axis docstring to document named-axis support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This PR improves the docstrings of all highlevel functions to state that they support named axes.
Closes #3488