Skip to content

Fix AnalysisBase.run misreading numpy boolean frame masks - #5480

Closed
barlowa124 wants to merge 2 commits into
MDAnalysis:developfrom
barlowa124:fix-np-bool-frames-mask
Closed

barlowa124 wants to merge 2 commits into
MDAnalysis:developfrom
barlowa124:fix-np-bool-frames-mask

Conversation

@barlowa124

Copy link
Copy Markdown

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_groups used isinstance(obj, bool), which does not match np.bool_ elements. With a mask like [True, False, True, False], the Python list form correctly selected frames 0 and 2 while the equivalent np.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__ in coordinates/base.py already handles both cases. This was the remaining unconverted site in the analysis path.

Changes

  • package/MDAnalysis/analysis/base.py: include np.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 both test_frame_slice and test_frame_slice_parallel.
  • CHANGELOG entry under 2.11.0 Fixes. Added my GitHub handle to AUTHORS.

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 full test_base.py suite reports 100 passed.

Fixes #5472.

Generated by Devin

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
barlowa124 force-pushed the fix-np-bool-frames-mask branch from a00b2bb to 266d057 Compare October 1, 2026 23:46
@read-the-docs-community

read-the-docs-community Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 MDAnalysis | 🛠️ Build #34891769 | 📁 Comparing 7c58ddd against latest (8b8875c)

  🔍 Preview build  

3 files changed
± index.html
± documentation_pages/analysis/wbridge_analysis.html
± _modules/MDAnalysis/analysis/base.html

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.87%. Comparing base (8b8875c) to head (7c58ddd).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@orbeckst orbeckst added the AI-assisted Generated with AI/LLM assistance label Oct 2, 2026
@orbeckst

orbeckst commented Oct 2, 2026

Copy link
Copy Markdown
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.

@orbeckst orbeckst closed this Oct 2, 2026
@barlowa124

Copy link
Copy Markdown
Author

5476 covers the same boolean-mask path and has merged.

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

Labels

AI-assisted Generated with AI/LLM assistance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnalysisBase.run() misinterpretation of NumPy booleans frame masks as integer frame indices

2 participants