Skip to content

Commit

Permalink
fix: ak.argcombinations should allow negative axis (#3301)
Browse files Browse the repository at this point in the history
* fix: ak.argcombinations should allow negative axis

* fix: ak.argcombinations should allow negative axis
  • Loading branch information
jpivarski authored Nov 13, 2024
1 parent 549b6a4 commit ab484af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/awkward/operations/ak_argcombinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,17 @@ def _impl(

axis = regularize_axis(axis, none_allowed=False)

if axis < 0:
raise ValueError("the 'axis' for argcombinations must be non-negative")
else:
with HighLevelContext(behavior=behavior, attrs=attrs) as ctx:
layout = ak._do.local_index(
ctx.unwrap(array, allow_record=False, primitive_policy="error"),
axis,
)
out = ak._do.combinations(
layout,
n,
replacement=replacement,
axis=axis,
fields=fields,
parameters=parameters,
with HighLevelContext(behavior=behavior, attrs=attrs) as ctx:
layout = ak._do.local_index(
ctx.unwrap(array, allow_record=False, primitive_policy="error"),
axis,
)
return ctx.wrap(out, highlevel=highlevel)
out = ak._do.combinations(
layout,
n,
replacement=replacement,
axis=axis,
fields=fields,
parameters=parameters,
)
return ctx.wrap(out, highlevel=highlevel)
22 changes: 22 additions & 0 deletions tests/test_3300_allow_negative_axis_in_argcombinations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

import awkward as ak


def test():
array = ak.Array([[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]])

assert ak.combinations(array, 2, axis=-1).tolist() == [
[(0.0, 1.1), (0.0, 2.2), (1.1, 2.2)],
[],
[(3.3, 4.4)],
[],
[(6.6, 7.7), (6.6, 8.8), (6.6, 9.9), (7.7, 8.8), (7.7, 9.9), (8.8, 9.9)],
]
assert ak.argcombinations(array, 2, axis=-1).tolist() == [
[(0, 1), (0, 2), (1, 2)],
[],
[(0, 1)],
[],
[(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)],
]

0 comments on commit ab484af

Please sign in to comment.