Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/pyarrow/table.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions python/pyarrow/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading