Skip to content

result of group aggregates with labels in reverse order can be wrong #868

@gdementen

Description

@gdementen

if the "step" between values is larger than the index of the last element.

>>> arr = ndtest(4)
>>> arr.sum('a1,a3')
4
>>> # this is wrong!
... arr.sum('a3,a1')
0
>>> arr['a3,a1'].sum()
4

What happens in the group aggregate case is that "lists" of labels are translated to slices when possible (ie, all elements are within a constant step of each other) so that the the aggregate is done on a view instead of a copy of the data. For negative slices it works too... except when the "step" is larger than the index of the last element (which has the smallest index), in which case the stop bound (which isn't included in slices) is negative, which is wrong (ie 'a3,a1' is translated to slice(3, -1, -2) which is equivalent to an empty slice.

Basically, the code in _range_to_slice should be fixed to handle this test case:

>>> _range_to_slice([3, 1], 4)
slice(3, 0, -2)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions