-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[Python] Add StructType attribute to access all its fields #30058
Copy link
Copy link
Closed
Milestone
Description
Currently when having a StructType, you can check the number of fields or get a specific field by index:
>>> struct_type = pa.struct([('a', pa.int64()), ('b', pa.float64())])
>>> struct_type.num_fields
2
>>> struct_type.get_field_index("a")
0
>>> struct_type[0]
pyarrow.Field<a: int64>and so that means you can actually get all fields by iterating:
>>> list(struct_type)
[pyarrow.Field<a: int64>, pyarrow.Field<b: double>]That's straightfoward code once you know this, but personally I don't find this very discoverable.
I think it would be nice to have some additional convenience attributes, such as .fields returning a list of all fields and .names returning a list of the field names (currently you need [f.name for f in struct_type] for this).
Reporter: Joris Van den Bossche / @jorisvandenbossche
Note: This issue was originally created as ARROW-14501. Please see the migration documentation for further details.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Type
Fields
Give feedbackNo fields configured for issues without a type.