You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/19 22:10:04 UTC

[GitHub] [arrow] wjones127 commented on a diff in pull request #13652: ARROW-17131: [Python] add StructType().field(): returns a field by name or index

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


##########
python/pyarrow/types.pxi:
##########
@@ -522,14 +563,29 @@ cdef class StructType(DataType):
         for i in range(len(self)):
             yield self[i]
 
+    def _field(self, int i):

Review Comment:
   I wonder if this should be `cdef`?
   ```suggestion
       cdef _field(self, int i):
   ```



##########
python/pyarrow/types.pxi:
##########
@@ -522,14 +563,29 @@ cdef class StructType(DataType):
         for i in range(len(self)):
             yield self[i]
 
+    def _field(self, int i):
+        """
+        Select a field by its numeric index.
+
+        Parameters
+        ----------
+        i : int
+
+        Returns
+        -------
+        pyarrow.Field
+        """
+        cdef int index = <int> _normalize_index(i, self.struct_type.num_fields())
+        return pyarrow_wrap_field(self.struct_type.field(index))
+
     def __getitem__(self, i):
         """
         Return the struct field with the given index or name.
         """
         if isinstance(i, (bytes, str)):
             return self.field_by_name(i)
         elif isinstance(i, int):
-            return self.field(i)
+            return self._field(i)

Review Comment:
   IIUC, the reason for definition of `_field()` is that our new `field()` method masked the parent class implementation, right? I wonder if this works just as well?
   
   ```suggestion
               return super().field(i)
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org