fenfeng9 opened a new issue, #50105:
URL: https://github.com/apache/arrow/issues/50105
### Describe the bug, including details regarding any error messages,
version, and platform.
### Description
Slicing a sparse union array produces incorrect logical values.
`to_pylist()` and scalar access on the slice return wrong results —a
non-null element is reported as null, or a value from the wrong position is
returned.
### Reproduce
```python
import pyarrow as pa
def main():
arr = pa.UnionArray.from_sparse(
pa.array([0, 0, 0], type=pa.int8()),
[pa.array([None, 20, 30])],
)
sliced = arr.slice(2)
print(f"pyarrow: {pa.__version__}")
print()
# Direct access on the original array is still correct.
expected_arr_2 = 30
actual_arr_2 = arr[2].as_py()
print(f"arr[2].as_py() expected: {expected_arr_2}")
print(f"arr[2].as_py() actual: {actual_arr_2}")
print()
# The sliced array should preserve the same logical value in to_pylist().
expected_sliced_pylist = [30]
actual_sliced_pylist = sliced.to_pylist()
print(f"sliced.to_pylist() expected: {expected_sliced_pylist}")
print(f"sliced.to_pylist() actual: {actual_sliced_pylist}")
print()
# Scalar access on the sliced array should also return the same value.
expected_sliced_0 = 30
actual_sliced_0 = sliced[0].as_py()
print(f"sliced[0].as_py() expected: {expected_sliced_0}")
print(f"sliced[0].as_py() actual: {actual_sliced_0}")
if __name__ == "__main__":
main()
```
### Result
```python
pyarrow: 24.0.0
arr[2].as_py() expected: 30
arr[2].as_py() actual: 30
sliced.to_pylist() expected: [30]
sliced.to_pylist() actual: [None]
sliced[0].as_py() expected: 30
sliced[0].as_py() actual: None
```
### Component(s)
C++
--
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]