diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi index 1abe4235c41..4aa2c56159d 100644 --- a/python/pyarrow/table.pxi +++ b/python/pyarrow/table.pxi @@ -555,8 +555,9 @@ cdef class ChunkedArray(_PandasConvertible): "If using `np.array(obj, copy=False)` replace it with " "`np.asarray(obj)` to allow a copy when needed" ) - # 'copy' can further be ignored because to_numpy() already returns a copy values = self.to_numpy() + if copy is True: + return np.array(values, dtype=dtype, copy=True) if dtype is None: return values return values.astype(dtype, copy=False) diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py index cb010f4387b..9637ae3e3aa 100644 --- a/python/pyarrow/tests/test_table.py +++ b/python/pyarrow/tests/test_table.py @@ -144,6 +144,16 @@ def test_chunked_array_to_numpy(): assert np.array_equal(arr1, arr2) +@pytest.mark.numpy +def test_chunked_array_array_copy_true_is_writable(): + data = pa.chunked_array([[1, 2, 3]]) + result = data.__array__(copy=True) + + assert result.flags.writeable + result[0] = 99 + assert result.tolist() == [99, 2, 3] + + def test_chunked_array_mismatch_types(): msg = "chunks must all be same type" with pytest.raises(TypeError, match=msg):