pitrou commented on code in PR #38008:
URL: https://github.com/apache/arrow/pull/38008#discussion_r1406527956


##########
python/pyarrow/scalar.pxi:
##########
@@ -1027,6 +1027,53 @@ cdef class ExtensionScalar(Scalar):
         return pyarrow_wrap_scalar(<shared_ptr[CScalar]> sp_scalar)
 
 
+cdef class VariableShapeTensorScalar(ExtensionScalar):
+    """
+    Concrete class for variable shape tensor extension scalar.
+    """
+
+    def to_numpy_ndarray(self):
+        # TODO: allow any permutation
+        """
+        Convert variable shape tensor extension scalar to a numpy array.
+        Note: ``permutation`` should be trivial (``None`` or ``[0, 1, ..., 
len(shape)-1]``).
+        """
+
+        if self.type.permutation is None or self.type.permutation == 
list(range(len(self.type.permutation))):
+            shape = self.value[0].values.to_pylist()
+            np_flat = np.asarray(self.value[1].values)
+            return np_flat.reshape(shape)
+        else:
+            raise ValueError(
+                'Only non-permuted tensors can be converted to numpy tensors.')

Review Comment:
   If it incurs a copy, then the code should be corrected not to? :-)



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