Skip to content

[Python] StructArray.from_array() should accept a type (in addition to names or fields) #42014

@jorisvandenbossche

Description

@jorisvandenbossche

If you have a struct type defined, and want to create a struct array from it given a set of child arrays, you currently can't direclty use StructArray.from_arrays because that method only accepts a list of fields. It's of course easy to get the fields from the struct type:

struct_type = pa.struct([("x", pa.float64()), ("y", pa.float64())])
arr = pa.array([0.1, 0.2])

struct_arr = pa.StructArray.from_arrays([arr, arr], fields=[struct_type.field(i) for i in range(struct_type.num_fields)])
# or simpler if you know a struct type is iterable
struct_arr = pa.StructArray.from_arrays([arr, arr], fields=list(struct_type))

But even easier would be to just accept the type as an argument directly, as a small added convenience.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions