-
Notifications
You must be signed in to change notification settings - Fork 2
Fix reverse slicing edge case #562
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
Conversation
This is coming from unexpected behavior of `Slice.indices`. The solution is to simply avoid using `.indices`. A MRE is nums = [0, 1, 2, 3, 4] sl = slice(None, None, -1) start, stop, step = sl.indices(len(nums)) print(nums[sl]) # [4, 3, 2, 1, 0] print(nums[start:stop:step]) # []
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is almost the same as getitem.py (list vs ilist)
Can code duplication be avoided?
weinbe58
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
In three places across the kirin code base a slice object would be converted into
start,stop,steptriples usingslice.indices, and then converted back into aslice.There is a subtle issue with this illustrated by the following snippet:
Specifically, the following is an example of a incorrect rewrite that happened as a consequence
This PR removes all usage of
slice.indicesand introduces some new unit tests.