Hi Artem,

I can't speak with authority on the subject, but I've been using "empty
struct". By empty I mean they don't have any child type.
When you create an array, there would still be one underlying "mask" array
to represent the presence of an element ({} vs null).

import pyarrow as pa

assert pa.StructArray.from_arrays(
    arrays=[],
    fields=[],
    mask=pa.array([True, False, True], pa.bool_()),
).to_pylist() == [None, {}, None]

On Tue, 25 Feb 2025 at 06:20, Артем Тарасов <artemtarasov...@gmail.com>
wrote:

> Hello everyone,
>
> I have a question regarding the StructType and its corresponding
> StructArray in Apache Arrow.
>
> From the documentation, I understand that StructType is categorized as a
> NestedType, which is a data type whose full structure depends "on one or
> more other child types". This implies that there should be at least one
> child type.
>
> However, I've noticed that there are no explicit checks for this
> requirement in the StructType constructor. Additionally, I've come across
> instances in the code where StructArray is constructed without children,
> such as in this example: link to code (
> https://github.com/apache/arrow/blob/main/cpp/src/arrow/record_batch.cc#L292
> ).
>
> My question is: Does the library officially support a StructType that does
> not have any children?
>
> Best regards,
> Artem
>

Reply via email to