apache / apache/arrow

[Python] `.slice` methods should accept Arrow scalar types

Offen
#51,145 2 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @YusefSyed Auf GitHub ansehen
Component: Python Type: enhancement
Vorherrschende Sprache
C++
Sterne
17.1k
Forks
4.3k
Ø Merge
3 T. 23 Std.
Gemergte PRs (30 T.)
101

Beschreibung

### Describe the enhancement requested

The `.slice` methods take two integers as arguments, but cannot take arrow integer types.

```python
import pyarrow as pa

a = pa.array([0, 1, 2, 3, 4, 5])

a.slice(0, 4)
#
# [
# 1,
# 2,
# 3,
# 4
# ]

a.slice(a[0], a[4])
# ---------------------------------------------------------------------------
# TypeError Traceback (most recent call last)
# Cell In[12], line 1
# ----> 1 a.slice(a[0], a[4])
#
# File pyarrow/array.pxi:1639, in pyarrow.lib.Array.slice()
# -> 1639 'Could not get source, probably due dynamically evaluated source code.'
#
# TypeError: '<' not supported between instances of 'pyarrow.lib.Int64Scalar' and 'int'
```

The same is true for tables:

```python
t = pa.Table.from_pydict({"a": a})

t.slice(a[0], a[4])
# ---------------------------------------------------------------------------
# TypeError Traceback (most recent call last)
# Cell In[13], line 1
# ----> 1 t.slice(a[0], a[4])

# File pyarrow/table.pxi:4299, in pyarrow.lib.Table.slice()
# -> 4299 'Could not get source, probably due dynamically evaluated source code.'

# TypeError: '<' not supported between instances of 'pyarrow.lib.Int64Scalar' and 'int'
```

This is not generally true of other methods. For example, `.take` is fine with getting an arrow array. I can even do `a[slice(a[0], a[0] + a[4])]`, where that `slice` contains pyarrow scalars.

I think it is kinda silly that if I have offsets for an arrow table in another arrow table I am having to convert those offsets to python integers (e.g. `t.slice(a[0].as_py(), a[4].as_py())`) or converting to indexing with a `slice` object.

### Component(s)

Python

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.