Skip to content

GH-49384: [Python] Respect copy=True in ChunkedArray.__array__#50561

Open
jingyi-zhao-01 wants to merge 2 commits into
apache:mainfrom
jingyi-zhao-01:GH-49384-copy-true-chunkedarray-final
Open

GH-49384: [Python] Respect copy=True in ChunkedArray.__array__#50561
jingyi-zhao-01 wants to merge 2 commits into
apache:mainfrom
jingyi-zhao-01:GH-49384-copy-true-chunkedarray-final

Conversation

@jingyi-zhao-01

@jingyi-zhao-01 jingyi-zhao-01 commented Jul 20, 2026

Copy link
Copy Markdown

Rationale for this change

ChunkedArray.__array__(copy=True) should respect NumPy's copy request. For a single-chunk ChunkedArray, the current path can return a zero-copy read-only NumPy view instead.

Closes #49384.

What changes are included in this PR?

  • Make ChunkedArray.__array__(copy=True) return a real NumPy copy.
  • Add a regression test for the single-chunk case.

Are these changes tested?

Yes:

python -m pytest python/pyarrow/tests/test_table.py -q

Are there any user-facing changes?

Yes. np.array(pa.chunked_array([[...]]), copy=True) now returns a writable copied NumPy array, matching the behavior users expect from copy=True.

AI assistance

I used an AI coding assistant while preparing this patch. I reviewed the change myself, kept it scoped to ChunkedArray.__array__, and verified it with the focused PyArrow table tests above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Single chunk ChunkedArray doesn't correctly respect copy in __array__method

1 participant