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
Implement slice support for sequence return types #590
Labels
enhancement
New feature or request
Comments
mtreinish
added a commit
to mtreinish/retworkx
that referenced
this issue
Apr 21, 2022
mtreinish
added a commit
to mtreinish/retworkx
that referenced
this issue
Apr 21, 2022
This commit adds support for dealing with slice inputs to custom sequence return types such as NodeIndices. Previously, if a slice was requested from a custom return type it would have raised a TypeError. With this commit now it will return a new container object with a copy of the data from the requested slice. Fixes Qiskit#590
mergify bot
pushed a commit
that referenced
this issue
Apr 27, 2022
* Add support for slice inputs to custom sequence return types This commit adds support for dealing with slice inputs to custom sequence return types such as NodeIndices. Previously, if a slice was requested from a custom return type it would have raised a TypeError. With this commit now it will return a new container object with a copy of the data from the requested slice. Fixes #590 * Fix windows build * Fix handling of negative length int index Previously if an integer index was passed to `__getitem__` with a value equal to the negative length of the sequence we would incorrectly raise an except when instead the first element should have been returned. This commit fixes the handling of that edge case. Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com> * Fix handling of negative steps in slices This commit fixes the handling of negative slices in sequence custom return types. Previouly using a negative step would cause a panic instead of correctly returning a reversed slice from the container. This commit corrects this so we can deal with negative slice steps too. * Apply suggestions from code review Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com> Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the expected enhancement?
For custom sequence return types we should support slice indexing in addition to just integers. For example if you ran something like:
It should return a
NodeIndices
object with the slice of 1 to 3. Right now if you want to get a slice you have to cast as a list which is less than ideal because it involves iterating and converting the entire object.The text was updated successfully, but these errors were encountered: