apache / apache/arrow

[C++][Python] Slicing a table with no columns returns a table with incorrect length.

Open
#30,894 3 comments 0 reactions 0 assignees View on GitHub
Component: C++ Component: Python good-first-issue Priority: Medium Status: needs champion Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

Python `[:]` slicing works on tables with no columns, because the slice inputs are normalized. But the `slice` method is inconsistent.
```python

In [1]: import pyarrow as pa

In [2]: table = pa.table({'col': range(3)})

In [3]: table.slice(1).num_rows
Out[3]: 2

In [4]: table.select([])[1:].num_rows
Out[4]: 2

In [5]: table.select([]).slice(1).num_rows
Out[5]: 3

In [6]: table.select([]).slice(1, 4).num_rows
Out[6]: 4
```

**Reporter**: [A. Coady](https://issues.apache.org/jira/browse/ARROW-15412) / @coady

**Note**: *This issue was originally created as [ARROW-15412](https://issues.apache.org/jira/browse/ARROW-15412). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Contributor guide

Open the contributing guide

Research direction

Reproduce the examples with pyarrow, comparing table.slice(1) and slicing table.select([])[1:]. Start at the C++/Python implementation behind the Table.slice entry point and trace how row counts are determined for tables with no columns. Done means slice offsets and lengths produce the same row counts as ordinary Python slicing, including the shown bounded slice.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.