Fix DeprecationWarning when setting header.dtype on NumPy 2.5+#76
Open
McHaillet wants to merge 1 commit into
Open
Fix DeprecationWarning when setting header.dtype on NumPy 2.5+#76McHaillet wants to merge 1 commit into
McHaillet wants to merge 1 commit into
Conversation
NumPy 2.5 deprecates assigning to .dtype on an existing array. Replace in-place dtype mutation with view()-based reinterpretation in mrcinterpreter.py and mrcobject.py. In update_header_from_data(), this means a header reference obtained before calling set_data() with byte-swapped data no longer reflects the byte-order change in place; callers must re-fetch mrc.header afterwards. The affected test has been updated accordingly. Fixes ccpem#75
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.
@colinpalmer Just a heads up, I thought I would have a fix at solving this issue with claude because it seemed simple enough, but that might not be the case.
Mainly the original code had this comment which this PR exactly changes. From the text it's not immediately clear to me what mrcfile is trying to achieve here specifically with dtype assigning:
but my guess its because of maintaining the original object, which is no longer possible with 2.5, so some fix is definitely needed.
Summary of the fix (closes #75):
2.5 deprecates in-place dtype assignment entirely (confirmed for plain ndarray too, not just recarray — no in-place-safe alternative exists).
one affected test (test_header_byte_order_is_changed_by_data_with_opposite_order) to re-fetch mrc.header instead.
Closes #75