Skip to content

Inaccurate typing / documentation of axis parameters #3488

@NicoWeio

Description

@NicoWeio

I was about to create a PR adding more specific typing (axis=Noneaxis: int | None = None to axis parameters in most high-level functions, but I noticed that #3238 added named axes. This is not reflected in the corresponding docstrings (axis (None or int): …), nor in the aforementioned type hints – with the exception of ak_moment.
Complicating things further, the therein-used type AxisName accepts any Hashable, which includes None, so if one were to use that in its current form everywhere, functions that don't allow None would no longer show type errors.
I'm new to this library and even newer to the development side of it, but the above does seem like an unintentional inconsistency. I'd be happy to help with fixing once it is decided how to.

@high_level_function()
def moment(
x,
n,
weight=None,
axis: AxisName = None,
*,
keepdims: bool = False,
mask_identity: bool = False,
highlevel: bool = True,
behavior: Mapping | None = None,
attrs: Mapping | None = None,
):
"""
Args:
x: The data on which to compute the moment (anything #ak.to_layout recognizes).
n (int): The choice of moment: `0` is a sum of weights, `1` is
#ak.mean, `2` is #ak.var without subtracting the mean, etc.
weight: Data that can be broadcasted to `x` to give each value a
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
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.

AxisName: tp.TypeAlias = tp.Hashable

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions