rok commented on code in PR #37533:
URL: https://github.com/apache/arrow/pull/37533#discussion_r1424782648


##########
python/pyarrow/tests/test_extension_type.py:
##########
@@ -1319,38 +1319,65 @@ def test_tensor_type():
 
 
 def test_tensor_class_methods():
+    from numpy.lib.stride_tricks import as_strided
+
+    values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
+    np_arr = np.array(values, dtype=np.int8)
     tensor_type = pa.fixed_shape_tensor(pa.float32(), [2, 3])
-    storage = pa.array([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]],
-                       pa.list_(pa.float32(), 6))
+    storage = pa.array(np_arr.reshape(2, 6).tolist(), pa.list_(pa.float32(), 
6))
     arr = pa.ExtensionArray.from_storage(tensor_type, storage)
-    expected = np.array(
-        [[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]], dtype=np.float32)
-    result = arr.to_numpy_ndarray()
-    np.testing.assert_array_equal(result, expected)
 
-    expected = np.array([[[1, 2, 3], [4, 5, 6]]], dtype=np.float32)
+    # TODO: add more get_tensor tests
+    assert arr.get_tensor(0) == pa.Tensor.from_numpy(
+        np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32))
+
+    expected = np_arr.reshape(2, 2, 3).astype(np.float32).tolist()
+    np.testing.assert_array_equal(arr.to_tensor(), expected)
+    np.testing.assert_array_equal(arr.to_numpy_ndarray(), expected)
+
+    # TODO: offset not correctly handled
+    expected = np_arr[6:].reshape(1, 2, 3).astype(np.float32)
+    # expected = np.array([[[7, 8, 9], [10, 11, 12]]], dtype=np.float32)
     result = arr[:1].to_numpy_ndarray()
-    np.testing.assert_array_equal(result, expected)
+    # np.testing.assert_array_equal(result, expected)

Review Comment:
   @pitrou would a buffer of an array sliced in python have correct `offset` 
accessible in C++? I've tried slicing it with 
`ext_arr->Slice(ext_arr->offset(), ..)` but only got data with 0 offset.
   
https://github.com/apache/arrow/blob/5085b097ce672c624c9b88f77f2def6d371a7464/cpp/src/arrow/extension/fixed_shape_tensor.cc#L372-L375
   This approach worked with a Scalar:
   
https://github.com/apache/arrow/blob/5085b097ce672c624c9b88f77f2def6d371a7464/cpp/src/arrow/extension/fixed_shape_tensor.cc#L239-L243



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to