Skip to content

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

Open
jingyi-zhao-01 wants to merge 1 commit into
apache:mainfrom
jingyi-zhao-01:main
Open

GH-49384: [Python] Respect copy=True in ChunkedArray.__array__#50541
jingyi-zhao-01 wants to merge 1 commit into
apache:mainfrom
jingyi-zhao-01:main

Conversation

@jingyi-zhao-01

@jingyi-zhao-01 jingyi-zhao-01 commented Jul 18, 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 codex 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.

@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@github-actions
github-actions Bot marked this pull request as draft July 18, 2026 08:32
@jingyi-zhao-01 jingyi-zhao-01 changed the title [Python] Enhance ChunkedArray to support writable numpy array when co… [Python] Respect copy=True in ChunkedArray.__array__ Jul 18, 2026
@jingyi-zhao-01 jingyi-zhao-01 changed the title [Python] Respect copy=True in ChunkedArray.__array__ GH-49384: [Python] Respect copy=True in ChunkedArray.__array__ Jul 18, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #49384 has been automatically assigned in GitHub to PR creator.

@jingyi-zhao-01
jingyi-zhao-01 marked this pull request as ready for review July 18, 2026 08:34
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