pitrou commented on code in PR #13652:
URL: https://github.com/apache/arrow/pull/13652#discussion_r937408868
##########
python/pyarrow/types.pxi:
##########
@@ -429,12 +429,23 @@ cdef class StructType(DataType):
Examples
--------
>>> import pyarrow as pa
+
+ Accessing fields using direct indexing:
+
>>> struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()})
>>> struct_type[0]
pyarrow.Field<x: int32>
>>> struct_type['y']
pyarrow.Field<y: string>
+ Accessing fields using ``field()``:
+
+ >>> struct_type.field(1)
+ pyarrow.Field<y: string>
+ >>> struct_type.field('x')
+ pyarrow.Field<x: int32>
+
+
Review Comment:
Stray newline here?
##########
python/pyarrow/types.pxi:
##########
@@ -526,12 +572,7 @@ cdef class StructType(DataType):
"""
Return the struct field with the given index or name.
Review Comment:
Add that it's an alias of `field`?
##########
python/pyarrow/types.pxi:
##########
@@ -526,12 +572,7 @@ cdef class StructType(DataType):
"""
Return the struct field with the given index or name.
Review Comment:
```suggestion
Return the struct field with the given index or name.
This is an alias of the ``field`` method.
```
##########
python/pyarrow/types.pxi:
##########
@@ -429,12 +429,23 @@ cdef class StructType(DataType):
Examples
--------
>>> import pyarrow as pa
+
+ Accessing fields using direct indexing:
+
>>> struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()})
>>> struct_type[0]
pyarrow.Field<x: int32>
>>> struct_type['y']
pyarrow.Field<y: string>
+ Accessing fields using ``field()``:
+
+ >>> struct_type.field(1)
+ pyarrow.Field<y: string>
+ >>> struct_type.field('x')
+ pyarrow.Field<x: int32>
+
+
Review Comment:
Also perhaps add a description for the final example below:
```suggestion
Creating a schema from the struct type's fields:
```
##########
python/pyarrow/types.pxi:
##########
@@ -494,6 +505,41 @@ cdef class StructType(DataType):
"""
return self.struct_type.GetFieldIndex(tobytes(name))
+ def field(self, i):
+ """
+ Select a field by its column name or numeric index.
+
+ Parameters
+ ----------
+ i : int or str
+
+ Returns
+ -------
+ pyarrow.Field
+
+ Examples
+ --------
+
+ >>> import pyarrow as pa
+ >>> struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()})
+
+ Select the second field:
+
+ >>> struct_type.field(1)
+ pyarrow.Field<y: string>
+
+ Select the field of the column named 'x':
Review Comment:
"column" is not part of the vocabulary for data types (you typically have
columns in a RecordBatch or Table, not in an Array).
```suggestion
Select the field named 'x':
```
##########
python/pyarrow/types.pxi:
##########
@@ -579,6 +620,23 @@ cdef class UnionType(DataType):
for i in range(len(self)):
yield self[i]
+ def field(self, i):
+ """
+ Return a child field by its numeric index.
+
+ Parameters
+ ----------
+ i : int
+
+ Returns
+ -------
+ pyarrow.Field
+ """
+ if isinstance(i, int):
+ return DataType.field(self, i)
+ else:
+ raise TypeError('Expected integer')
+
def __getitem__(self, i):
"""
Return a child field by its index.
Review Comment:
Add that it's an alias of field?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]