jorisvandenbossche commented on code in PR #13652:
URL: https://github.com/apache/arrow/pull/13652#discussion_r925414671


##########
python/pyarrow/types.pxi:
##########
@@ -494,6 +505,36 @@ 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':
+
+        >>> struct_type.field('x')
+        pyarrow.Field<x: int32>
+        """
+        return self.__getitem__(i)

Review Comment:
   I would maybe do it the other way around: move the current code of getitem 
here, and in getitem call `return self.field(key)` (that feels a bit more 
typical pattern than explicitly calling a dunder method here)



-- 
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]

Reply via email to