Skip to content

[C++][Python] StructArray flattening aborts on a sparse union child and drops nulls on a run-end encoded child #55958

Backlog

Description

@AndreaBozzo

Describe the bug, including details regarding any error messages, version, and platform.

StructArray::GetFlattenedField sets buffers[0] on the child whatever its type. A sparse union has no validity bitmap, so SparseUnionArray::SetData hits ARROW_CHECK_EQ(data_->buffers[0], nullptr) and the process aborts. A run-end encoded child takes no validity bitmap either, so the struct's null row is silently lost. Both StructArray.flatten() and RecordBatch.from_struct_array() go through it.

pyarrow 26.0.1, Windows 11, Python 3.15. The code is the same on main.

import pyarrow as pa

mask = pa.array([False, True, False])

ree = pa.RunEndEncodedArray.from_arrays([2, 3], [10, 20])
st = pa.StructArray.from_arrays([ree], names=["r"], mask=mask)
print(st.flatten()[0].to_pylist(), flush=True)  # [10, 10, 20], expected [10, None, 20]

union = pa.UnionArray.from_sparse(pa.array([0, 0, 0], pa.int8()), [pa.array([10, 20, 30])])
st = pa.StructArray.from_arrays([union], names=["u"], mask=mask)
st.flatten()
# array_nested.cc:1267: Check failed: (data_->buffers[0]) == (nullptr)
# and the interpreter exits

An int64 or null child works as expected. I would expect the null row to reach the run-end encoded and union children, or an error. A check failure that kills the interpreter can't be caught from Python.

Component(s)

C++, Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions