You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jorisvandenbossche (via GitHub)" <gi...@apache.org> on 2023/06/27 12:21:35 UTC

[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #35582: GH-34787: [Python] Accept zero_copy_only=False for ChunkedArray.to_numpy

jorisvandenbossche commented on code in PR #35582:
URL: https://github.com/apache/arrow/pull/35582#discussion_r1243642772


##########
python/pyarrow/tests/test_array.py:
##########
@@ -168,6 +168,28 @@ def test_to_numpy_zero_copy():
     np.testing.assert_array_equal(np_arr, expected)
 
 
+def test_chunked_array_to_numpy_zero_copy():
+    elements = [[2, 2, 4], [4, 5, 100]]
+
+    chunked_arr = pa.chunked_array(elements)
+
+    msg = "zero_copy_only must be False for pyarrow.ChunkedArray.to_numpy"
+
+    with pytest.raises(ValueError, match=msg):
+        chunked_arr.to_numpy(zero_copy_only=True)
+
+    np_arr = chunked_arr.to_numpy()
+
+    chunked_arr = None
+    import gc
+    gc.collect()
+
+    # Ensure base is still valid
+    assert np_arr.base is not None

Review Comment:
   I am not sure this part is needed here, as this is not actually zero copy (the base is still set, because we concatenate on the arrow side, and then still keep this concatenated buffer alive through a capsule as the numpy array's base).



-- 
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-unsubscribe@arrow.apache.org

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