Skip to content

Flumpy: Copy read-only arrays when converting to flex#876

Merged
ndevenish merged 2 commits intocctbx:mainfrom
ndevenish:numpy_ro
Feb 13, 2026
Merged

Flumpy: Copy read-only arrays when converting to flex#876
ndevenish merged 2 commits intocctbx:mainfrom
ndevenish:numpy_ro

Conversation

@ndevenish
Copy link
Collaborator

Recently, when pandas 3.0 was released, we ran into ValueError: array is not writeable errors in the DIALS tests.

Pandas 3.0+ specifically changed the default for all internal numpy arrays to be read-only with Copy-on-Write semantics. This meant that every instance where we were converting from pandas->flex now threw an error when a new mutable handle to the numpy data were sought.

Copying the array is slightly more expensive, but ensures that we never violate the read-only semantics of the underlying array. From a brief survey, it looks like the only places we were relying on this were lookups and conversions that didn't end up trying to write, but it is safer to just prevent the issue from ever happening rather than relying on people to remember not to write to converted arrays.

ndevenish and others added 2 commits February 12, 2026 15:17
This problem was specifically encountered with pandas 3.0+, which changed the
default for all internal numpy arrays to read-only with Copy-on-Write semantics.
This meant that every instance where we were converting from pandas->flex
now threw an error when a new mutable handle to the numpy data were sought.

Copying the array is slightly more expensive, but ensures that we never violate the
read-only semantics of the underlying array. From a brief survey, it looks like
the only places we were relying on this were lookups and conversions that didn't
end up trying to write, but it is safer to just prevent the issue from ever happening
rather than relying on people to remember not to write to converted arrays.
@ndevenish
Copy link
Collaborator Author

Fixes dials/dials#3086

@ndevenish ndevenish merged commit 350c5db into cctbx:main Feb 13, 2026
20 of 21 checks passed
@ndevenish ndevenish deleted the numpy_ro branch February 13, 2026 09:48
dwmoreau pushed a commit that referenced this pull request Feb 14, 2026
* Flumpy: Copy read-only arrays when converting to flex

This problem was specifically encountered with pandas 3.0+, which changed the
default for all internal numpy arrays to read-only with Copy-on-Write semantics.
This meant that every instance where we were converting from pandas->flex
now threw an error when a new mutable handle to the numpy data were sought.

Copying the array is slightly more expensive, but ensures that we never violate the
read-only semantics of the underlying array. From a brief survey, it looks like
the only places we were relying on this were lookups and conversions that didn't
end up trying to write, but it is safer to just prevent the issue from ever happening
rather than relying on people to remember not to write to converted arrays.

* Rename newsfragments/XXX.bugfix to newsfragments/876.bugfix

---------

Co-authored-by: DiamondLightSource-build-server <DiamondLightSource-build-server@users.noreply.github.com>
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.

2 participants