rok commented on code in PR #37533:
URL: https://github.com/apache/arrow/pull/37533#discussion_r1424679448
##########
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:
Offset of sliced array is not correctly handled yet. Still needs to be
solved.
--
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]