Copilot commented on code in PR #50430:
URL: https://github.com/apache/arrow/pull/50430#discussion_r3631017782
##########
python/pyarrow/array.pxi:
##########
@@ -2776,6 +2820,16 @@ cdef class ListArray(BaseListArray):
Concrete class for Arrow arrays of a list data type.
"""
+ cdef object _getitem_py(self, int64_t i, object maps_as_pydicts):
+ cdef CListArray* arr = <CListArray*> self.ap
+ if arr.IsNull(i):
+ return None
+ if self._children_cache is None:
+ self._children_cache = pyarrow_wrap_array(arr.values())
+ cdef Array values = <Array> self._children_cache
+ cdef int64_t j, start = arr.value_offset(i), end = arr.value_offset(i
+ 1)
+ return [values._getitem_py(j, maps_as_pydicts) for j in range(start,
end)]
Review Comment:
ListArray/LargeListArray/FixedSizeListArray _getitem_py uses
arr.value_offset(i)/value_offset(i+1), but in
python/pyarrow/includes/libarrow.pxd these methods are currently declared with
an `int` parameter. Cython will cast `i` (int64_t) down to `int` before
calling, which can truncate indices for arrays with length > INT_MAX and
produce incorrect start/end offsets (and thus incorrect results / potential
crashes). This also affects MapArray._getitem_py (uses CListArray.value_offset)
and the LargeListArray/FixedSizeListArray implementations in this file.
Please update the libarrow.pxd declarations for these list-like
value_offset/value_length methods to take `int64_t` (matching the C++
signatures), or avoid the truncating call path (e.g., use raw_value_offsets()
where available).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]