You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "danepitkin (via GitHub)" <gi...@apache.org> on 2023/06/22 21:00:57 UTC

[GitHub] [arrow] danepitkin commented on a diff in pull request #36242: GH-34886: [Python] Add correct __array__ numpy conversion for Table and RecordBatch

danepitkin commented on code in PR #36242:
URL: https://github.com/apache/arrow/pull/36242#discussion_r1239024807


##########
python/pyarrow/table.pxi:
##########
@@ -1487,6 +1487,16 @@ cdef class _Tabular(_PandasConvertible):
 
         return _PyArrowDataFrame(self, nan_as_null, allow_copy)
 
+    def __array__(self, dtype=None):
+        column_arrays = [
+            np.asarray(self.column(i), dtype=dtype) for i in range(self.num_columns)
+        ]
+        if column_arrays:
+            arr = np.stack(column_arrays, axis=1)
+        else:
+            arr = np.empty((self.num_rows, 0), dtype=dtype)

Review Comment:
   Just out of curiosity, is it possible to have `self.num_rows > 0` in this case? I would imagine that if there are no columns then there are no rows.



##########
python/pyarrow/table.pxi:
##########
@@ -1487,6 +1487,16 @@ cdef class _Tabular(_PandasConvertible):
 
         return _PyArrowDataFrame(self, nan_as_null, allow_copy)
 
+    def __array__(self, dtype=None):

Review Comment:
   nit: should we maintain alphabetization of methods (ignoring the `__init__` method)?



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