Skip to content

BUG: reject read-only arrays in replace - #632

Open
AryanRG wants to merge 1 commit into
pydata:masterfrom
AryanRG:fix-replace-readonly
Open

AryanRG wants to merge 1 commit into
pydata:masterfrom
AryanRG:fix-replace-readonly

Conversation

@AryanRG

@AryanRG AryanRG commented Nov 16, 2026

Copy link
Copy Markdown

bn.replace writes into read-only arrays. It silently changes an array with writeable=False, and a read-only memory-mapped array can crash the process. bn.slow.replace already raises ValueError.

Check writeability before entering the C kernels so replace raises before touching the array. Added one regression test, which fails on the original code.

Read-only inputs now raise even when there is nothing to replace, consistent with NumPy assignment.

The full suite passes locally with 209 passed and 1 expected failure on macOS arm64, Python 3.12 and NumPy 2.5.4. The read-only memmap reproduction also raises cleanly with the fix.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant