Skip to content
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

fix: off-by-one error in run_lengths #2093

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/awkward/operations/ak_run_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def lengths_of(data, offsets):
# To consider only the interior boundaries, we ignore the start and end
# offset values. These can be repeated with empty sublists, so we mask them out.
is_interior = backend.nplike.logical_and(
0 < offsets, offsets < len(data) - 1
0 < offsets, offsets < len(data)
)
interior_offsets = offsets[is_interior]
diffs[interior_offsets - 1] = True
Expand Down
11 changes: 11 additions & 0 deletions tests/test_0733_run_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ def test():
]


def test_all_same():
array = ak.Array([[3, 3, 3, 3], [3], [], [3, 3, 3], [3]])
assert ak.operations.run_lengths(array).to_list() == [
[4],
[1],
[],
[3],
[1],
]


def test_groupby():
array = ak.Array(
[
Expand Down