Copilot commented on code in PR #50929:
URL: https://github.com/apache/arrow/pull/50929#discussion_r3902946797
##########
python/pyarrow/array.pxi:
##########
@@ -1841,6 +1841,28 @@ cdef class Array(_PandasConvertible):
array = array.copy()
return array
+ def to_tensor(self):
+ """
+ Convert this array to a pyarrow.Tensor.
+
+ This is supported when the data can reasonably be understood as a
+ multi-dimensional numeric tensor, such as numeric arrays (1D), nested
+ fixed size list arrays, and fixed shape tensor arrays.
+ The resulting tensor has a row major layout with the array elements
+ as the first dimension.
+ Null values are ignored, leaving the corresponding entries of the
+ tensor with unspecified values.
+ The conversion is zero-copy.
+
+ Returns
+ -------
+ pyarrow.Tensor
+ """
+ cdef shared_ptr[CTensor] ctensor
+ with nogil:
+ ctensor = GetResultValue(self.ap.ToTensor())
Review Comment:
`Array.to_tensor()` docstring says null values are ignored, and the PR
description notes nulls are supported, but the binding calls
`self.ap.ToTensor()` with the C++ default `allow_nulls=false`, which rejects
arrays with nulls. Consider exposing an `allow_nulls` keyword (and wiring it
through the Cython pxd signature) or explicitly passing `allow_nulls=true`
here, and add a Python test covering null-handling to prevent regressions.
--
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]