Skip to content

[Python] Slicing array can lead to negative length #28623

@asfimport

Description

@asfimport

Slice an arrow array can lead to a negative length, when instead it should never be smaller than 0.

arr = pa.array(range(10))
assert len(arr[-9:-20]) == 0

Array.length() returns -1 which makes the previous snippet crash as Python never accepts length < 0

In particular if you have Python in debug mode it will explicitly fail the related assertion
Assertion failed: (len >= 0 || PyErr_Occurred()), function PyObject_Size, file Objects/abstract.c, line 61

Reporter: Alessandro Molina / @amol-
Assignee: Alessandro Molina / @amol-

Related issues:

Note: This issue was originally created as ARROW-12893. Please see the migration documentation for further details.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions