You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "fenfeng9 (via GitHub)" <gi...@apache.org> on 2026/06/05 13:52:29 UTC
[I] [C++] Sliced sparse union element access can return incorrect values [arrow]
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: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [C++] Sliced sparse union element access can return incorrect values [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on issue #50105:
URL: https://github.com/apache/arrow/issues/50105#issuecomment-4671504370
Issue resolved by pull request 50108
https://github.com/apache/arrow/pull/50108
--
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] [C++] Sliced sparse union element access can return incorrect values [arrow]
Posted by "fenfeng9 (via GitHub)" <gi...@apache.org>.
fenfeng9 commented on issue #50105:
URL: https://github.com/apache/arrow/issues/50105#issuecomment-4632287224
I think this bug is in the sparse-union logical null path here:
https://github.com/apache/arrow/blob/e16067a78ce4e7325a258bb2ae1ef73211cc7d46/cpp/src/arrow/array/data.cc#L72-L77
and here:
https://github.com/apache/arrow/blob/e16067a78ce4e7325a258bb2ae1ef73211cc7d46/cpp/src/arrow/array/data.cc#L697-L702
`IsNullSparseUnion` checks child nullness with `i`, but it should use `data.offset + i`. Likewise, `ArraySpan::IsNullSparseUnion` should use `this->offset + i` instead of `i`. Otherwise, sliced sparse unions can return incorrect logical values.
I have verified the fix locally and will open a PR.
--
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] [C++] Sliced sparse union element access can return incorrect values [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou closed issue #50105: [C++] Sliced sparse union element access can return incorrect values
URL: https://github.com/apache/arrow/issues/50105
--
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