Skip to content

[Python] BUG: Empty slicing an array backwards beyond the start should be empty #40642

Closed

Description

@mroeschke

Describe the bug, including details regarding any error messages, version, and platform.

I think post #39240, slicing with an empty slice under the same conditions returns the first element when the result should be empty

In [14]: import pyarrow as pa
    ...: print(pa.__version__)
    ...: array = pa.chunked_array([list("abcde")])
    ...: array[slice(-6, -6, -1)]
16.0.0.dev318
Out[14]: 
<pyarrow.lib.ChunkedArray object at 0x11a1ce4d0>
[
  [
    "a"
  ]
]

In [15]: list("abcde")[slice(-6, -6, -1)]
Out[15]: []

cc @LucasG0 @jorisvandenbossche

Component(s)

Python

Activity

  1. jorisvandenbossche commented on Mar 19, 2024

    @jorisvandenbossche
    Member

    Thanks for the catch! Yet another annoying corner case ..

    I was wondering if there isn't some existing functionality to "normalize" slice objects, and https://stackoverflow.com/questions/6246084/sanitize-python-slice pointed to https://docs.python.org/3/reference/datamodel.html#slice.indices

    We could test if that helps for us. Although for the case above it still gives negative start/stop values .. :

    In [3]: slice(-6, -6, -1).indices(5)
    Out[3]: (-1, -1, -1)
    
  2. jorisvandenbossche commented on Mar 19, 2024

    @jorisvandenbossche
    Member

    (and so this case actually worked before, so going to mark as critical for 16.0)

  3. added this to the 16.0.0 milestone on Mar 19, 2024
  4. LucasG0 commented on Mar 20, 2024

    @LucasG0
    Contributor

    Using slices.indices seems to be a good call, thanks @jorisvandenbossche. I do not think still having negative values is an issue here, I created #40682.

  5. changed the title [-]BUG: Empty slicing an array backwards beyond the start should be empty[/-] [+][Python] BUG: Empty slicing an array backwards beyond the start should be empty[/+] on Mar 20, 2024
  6. raulcd commented on Apr 9, 2024

    @raulcd
    Member

    I am moving this to 17.0.0. Let me know if this is required for the 16.0.0 release.

  7. modified the milestones: 16.0.0, 17.0.0 on Apr 9, 2024
  8. jorisvandenbossche commented on Apr 9, 2024

    @jorisvandenbossche
    Member

    Moved this back to 16.0, because it is a regression that we caused ourselves that for now only lives on main, so we can prevent this gets released. Will look into updating/merging the PR.

  9. added a commit that references this issue on Apr 9, 2024
  10. jorisvandenbossche commented on Apr 9, 2024

    @jorisvandenbossche
    Member

    Resolved by #40682

  11. jorisvandenbossche commented on Apr 9, 2024

    @jorisvandenbossche
    Member

    @raulcd not fully familiar with the cherry-picking script, but the PR was pointing to an older already closed issues, and I only renamed it to point to this issue after merging with the merge script. Just mentioning in case that might affect it getting picked up by the backporting.

  12. added a commit that references this issue on Apr 10, 2024
  13. raulcd commented on Apr 10, 2024

    @raulcd
    Member

    @jorisvandenbossche this has been cherry-picked to the 16.0.0 maintenance branch. The cherry-pick script picked it up without further action on my side.

  14. added a commit that references this issue on May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions