jorisvandenbossche commented on code in PR #36242:
URL: https://github.com/apache/arrow/pull/36242#discussion_r1245514344
##########
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:
Yes, that is possible, you can have a table with a know number of rows but
without columns:
```
In [16]: table = pa.table({'a': [1, 2, 3]}).select([])
In [17]: table
Out[17]:
pyarrow.Table
----
In [18]: table.num_rows
Out[18]: 3
In [19]: table.num_columns
Out[19]: 0
```
--
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]