AlenkaF commented on code in PR #34883:
URL: https://github.com/apache/arrow/pull/34883#discussion_r1162369729
##########
python/pyarrow/array.pxi:
##########
@@ -3076,6 +3076,113 @@ cdef class ExtensionArray(Array):
return Array._to_pandas(self.storage, options, **kwargs)
+class FixedShapeTensorArray(ExtensionArray):
+ """
+ Concrete class for fixed shape tensor extension arrays.
+
+ Examples
+ --------
+ Define the extension type for tensor array
+
+ >>> import pyarrow as pa
+ >>> tensor_type = pa.fixed_shape_tensor(pa.int32(), [2, 2])
+
+ Create an extension array
+
+ >>> arr = [[1, 2, 3, 4], [10, 20, 30, 40], [100, 200, 300, 400]]
+ >>> storage = pa.array(arr, pa.list_(pa.int32(), 4))
+ >>> pa.ExtensionArray.from_storage(tensor_type, storage)
+ <pyarrow.lib.FixedShapeTensorArray object at ...>
+ [
+ [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ [
+ 10,
+ 20,
+ 30,
+ 40
+ ],
+ [
+ 100,
+ 200,
+ 300,
+ 400
+ ]
+ ]
+ """
+
+ def to_numpy_ndarray(self):
+ """
+ Convert fixed shape tensor extension array to a numpy array (with
dim+1).
+
+ Note: The method doesn't take into account ``permutation`` and
``dim_names``
+ parameter therefore this information will be lost.
+ """
Review Comment:
Trivial permutation should be equal to None (no permutation), I think? Then
we could just check for non None values?
Also, I feel this is to strict as the user might want to use the information
about the permutation themselves and permute the ndarray afterwords like I have
suggested in the docs example:
https://github.com/apache/arrow/blame/902aa069002e8a470a5f19d5e0137a600e85b66b/docs/source/python/extending_types.rst#L466-L538
(which they can not do if we throw an error).
You mention cases where information about the ordering could be lost and the
user would have no way of correcting it - I will try to find a specific case
that would support this so I am sure we are on the same page and we could have
a better idea about what would be best.
--
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]