You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Joris Van den Bossche (Jira)" <ji...@apache.org> on 2021/10/28 11:20:00 UTC
[jira] [Created] (ARROW-14501) [Python] Add StructType attribute to
access all its fields
Joris Van den Bossche created ARROW-14501:
---------------------------------------------
Summary: [Python] Add StructType attribute to access all its fields
Key: ARROW-14501
URL: https://issues.apache.org/jira/browse/ARROW-14501
Project: Apache Arrow
Issue Type: Improvement
Components: Python
Reporter: Joris Van den Bossche
Currently when having a StructType, you can check the number of fields or get a specific field by index:
{code}
>>> 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>
{code}
and so that means you can actually get all fields by iterating:
{code}
>>> list(struct_type)
[pyarrow.Field<a: int64>, pyarrow.Field<b: double>]
{code}
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).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)