aad1tyaaaaa opened a new pull request, #1057:
URL: https://github.com/apache/arrow-nanoarrow/pull/1057
`ToColumnsPysequenceConverter`, which backs `to_columns_pysequence()`,
visits each child of a struct array with the child's own offset and length and
ignores the parent's. When a struct array has an offset (a slice), or children
longer than the parent, the columns come back with the wrong rows:
```python
import nanoarrow as na
from nanoarrow import visitor
array = na.c_array_from_buffers(
na.struct({"col1": na.int32(), "col2": na.bool_()}),
length=4,
buffers=[None],
children=[
na.c_array([1, 2, 3, 4], na.int32()),
na.c_array([1, None, 1, 0], na.bool_()),
],
)
visitor.ToColumnsPysequenceConverter.visit(array[2:])
# ValueError: Null present with null_handler=nulls_forbid()
# (the two selected rows have no nulls; the null is in the skipped first
rows)
```
Without the null, it returns all four rows instead of the last two. The same
thing happens with
`na.Array(pa_struct_array.slice(2)).to_columns_pysequence()`, because pyarrow
exports a sliced `StructArray` with the offset on the parent. `to_pylist()` and
`iter_tuples()` already handle this case correctly.
This change overrides `_set_array()` in the converter. When the struct has
an offset or its children are longer than it, the converter rebuilds the struct
with each child sliced to `[offset, offset + length)`, so the child visitors
see the right window. The parent null check still runs first, so struct arrays
with nulls still raise the same error. The rebuilt struct drops its validity
buffer, which is safe because it has no nulls.
`test_convert_columns_with_offset` in `tests/test_visitor.py` covers a
sliced struct and a struct whose children are longer than it. It fails without
the change and passes with it. With the change, `pytest tests` gives 369
passed, 5 skipped, 1 failed. The failure is `test_iterator_timestamp_tz`, which
fails because there's no tzdata on this Windows machine and is unrelated. I
built from source on Windows with MSVC.
(Written with help from Claude Code.)
--
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]