You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "ivirshup (via GitHub)" <gi...@apache.org> on 2026/09/03 00:14:07 UTC
[I] [python] `.slice` methods should accept Arrow scalar types [arrow]
ivirshup opened a new issue, #51145:
URL: https://github.com/apache/arrow/issues/51145
### 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)
# <pyarrow.lib.Int64Array object at 0x798d8fec2ce0>
# [
# 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] `.slice` methods should accept Arrow scalar types [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF closed issue #51145: [Python] `.slice` methods should accept Arrow scalar types
URL: https://github.com/apache/arrow/issues/51145
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] `.slice` methods should accept Arrow scalar types [arrow]
Posted by "YusefSyed (via GitHub)" <gi...@apache.org>.
YusefSyed commented on issue #51145:
URL: https://github.com/apache/arrow/issues/51145#issuecomment-5535944392
take
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] `.slice` methods should accept Arrow scalar types [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on issue #51145:
URL: https://github.com/apache/arrow/issues/51145#issuecomment-5829384609
Issue resolved by pull request 51160
https://github.com/apache/arrow/pull/51160
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] `.slice` methods should accept Arrow scalar types [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on issue #51145:
URL: https://github.com/apache/arrow/issues/51145#issuecomment-5617017198
Thanks for the issue @ivirshup
The difference between `.take` and `.slice` is that they take two different code paths. `.take` goes through the compute module code path, where [`_pack_compute_args`](https://github.com/apache/arrow/blob/926885f1b1ede73badd24c2e6f63c9429441e99a/python/pyarrow/_compute.pyx#L494) does the type mapping, then C++ compute functions are all called with `arrow::Datum` arguments. Whereas the `.slice` code path goes to the C++ `Array::Slice` which expects `int64_t offset` and `int64_t length`.
I agree, `.slice` behavior could be improved on the Python side. Will look at the PR now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org