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


##########
python/pyarrow/tests/test_extension_type.py:
##########
@@ -1353,6 +1386,70 @@ def test_tensor_class_methods():
         arr.to_numpy_ndarray()
 
 
[email protected]("value_type", (np.int8, np.int32, np.int64, 
np.float64))
+def test_variable_shape_tensor_class_methods(value_type):
+    ndim = 2
+    shape_type = pa.list_(pa.uint32(), ndim)
+    arrow_type = pa.from_numpy_dtype(value_type)
+    tensor_type = pa.variable_shape_tensor(
+        arrow_type,
+        ndim,
+        dim_names=["H", "W"],
+        permutation=[0, 1],
+        uniform_shape=[None, None],
+    )
+    fields = [pa.field("shape", shape_type), pa.field("data", 
pa.list_(arrow_type))]
+
+    shapes = pa.array([[2, 3], [2, 1]], shape_type)
+    values = pa.array([[1, 2, 3, 4, 5, 6], [7, 8]], pa.list_(arrow_type))
+    struct_arr = pa.StructArray.from_arrays([shapes, values], fields=fields)
+    arr = pa.ExtensionArray.from_storage(tensor_type, struct_arr)
+    basic_arr = pa.ExtensionArray.from_storage(
+        pa.variable_shape_tensor(arrow_type, ndim), struct_arr
+    )
+
+    storage = pa.array(
+        [([2, 3], [1, 2, 3, 4, 5, 6]), ([2, 1], [7, 8])], 
type=pa.struct(fields)
+    )
+    assert pa.ExtensionArray.from_storage(tensor_type, storage).equals(arr)
+
+    assert arr.type == tensor_type
+
+    ndarray_list = [
+        np.array([[1, 2, 3], [4, 5, 6]], dtype=value_type),
+        np.array([[7], [8]], dtype=value_type),
+    ]
+    assert all(zip(x == y for x, y in zip(arr.to_numpy_ndarray(), 
ndarray_list)))

Review Comment:
   Ah, right. It would be more idiomatic (and more helpful in case of failures) 
to use something like 
https://numpy.org/doc/stable/reference/generated/numpy.testing.assert_array_equal.html
 , though.



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