diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py index 2dce1e613d6a6..d673f956527aa 100644 --- a/python/pyarrow/tests/test_types.py +++ b/python/pyarrow/tests/test_types.py @@ -693,6 +693,8 @@ def test_struct_type(): assert list(ty) == fields assert ty[0].name == 'a' assert ty[2].type == pa.int32() + assert ty.names == [f.name for f in ty] + assert ty.fields == list(ty) with pytest.raises(IndexError): assert ty[3] diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index ab20d74dd997e..039870accddcb 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -1025,6 +1025,33 @@ cdef class StructType(DataType): def __reduce__(self): return struct, (list(self),) + @property + def names(self): + """ + Lists the field names. + + Examples + -------- + >>> import pyarrow as pa + >>> struct_type = pa.struct([('a', pa.int64()), ('b', pa.float64()), ('c', pa.string())]) + >>> struct_type.names + ['a', 'b', 'c'] + """ + return [f.name for f in self] + + @property + def fields(self): + """ + Lists all fields within the StructType. + + Examples + -------- + >>> import pyarrow as pa + >>> struct_type = pa.struct([('a', pa.int64()), ('b', pa.float64()), ('c', pa.string())]) + >>> struct_type.fields + [pyarrow.Field, pyarrow.Field, pyarrow.Field] + """ + return list(self) cdef class UnionType(DataType): """