Fix AnalysisBase.run misreading numpy boolean frame masks - #5480
Closed
barlowa124 wants to merge 2 commits into
Closed
barlowa124 wants to merge 2 commits into
barlowa124 wants to merge 2 commits into
Conversation
The boolean-mask detection in _setup_computation_groups checked isinstance(obj, bool), which misses np.bool_ elements. A numpy boolean array passed via frames= was therefore used as integer indices and the analysis silently ran on the wrong frames. Include np.bool_ in the type check so numpy masks are handled like Python boolean lists. Fixes MDAnalysis#5472.
barlowa124
force-pushed
the
fix-np-bool-frames-mask
branch
from
October 1, 2026 23:46
a00b2bb to
266d057
Compare
Documentation build overview
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5480 +/- ##
========================================
Coverage 93.87% 93.87%
========================================
Files 182 182
Lines 22522 22522
Branches 3206 3206
========================================
Hits 21143 21143
Misses 917 917
Partials 462 462 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
This appears to be an AI-generated duplicate of PR #5476 ; furthermore, our standard template was ignored and replaced with generated content. Therefore, I am closing this PR. |
Author
|
5476 covers the same boolean-mask path and has merged. |
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.
Summary
Fixes #5472.
AnalysisBase.run(frames)accepted a NumPy boolean array but treated it as integer frame indices because the mask detection in_setup_computation_groupsusedisinstance(obj, bool), which does not matchnp.bool_elements. With a mask like[True, False, True, False], the Python list form correctly selected frames 0 and 2 while the equivalentnp.bool_array silently ran the analysis on frames[1, 0, 1, 0].The type check now accepts
np.bool_, so NumPy boolean masks behave identically to Python boolean lists. The trajectory-level__getitem__incoordinates/base.pyalready handles both cases. This was the remaining unconverted site in the analysis path.Changes
package/MDAnalysis/analysis/base.py: includenp.bool_in the mask-detection isinstance check.testsuite/MDAnalysisTests/analysis/test_base.py: added the NumPy-bool-array parametrization (same expected frames as the existing bool-list case) to bothtest_frame_sliceandtest_frame_slice_parallel.Verification
Verification used a 4-frame MEMORY trajectory via
AnalysisFromFunction. Pre-change the mask produced the wrong frame sequence, and post-change it matches the Python-list result. The fulltest_base.pysuite reports 100 passed.Fixes #5472.
Generated by Devin