Flumpy: Copy read-only arrays when converting to flex#876
Merged
ndevenish merged 2 commits intocctbx:mainfrom Feb 13, 2026
Merged
Flumpy: Copy read-only arrays when converting to flex#876ndevenish merged 2 commits intocctbx:mainfrom
ndevenish merged 2 commits intocctbx:mainfrom
Conversation
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.
Collaborator
Author
|
Fixes dials/dials#3086 |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recently, when pandas 3.0 was released, we ran into
ValueError: array is not writeableerrors 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.