Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed high dimensional GroupBase indexing. #4656

Merged
merged 3 commits into from
Aug 22, 2024

Conversation

MattTDavies
Copy link
Contributor

@MattTDavies MattTDavies commented Aug 15, 2024

Fixes #4647
This does not fix the underlying "Frankenatoms" issue, but stops it from occuring due to GroupBase indexing by raising an error if improperly shaped indices are provided.

Changes made in this Pull Request:

  • Added test confirming 2d index raises an IndexError.
  • Added a dimensionality check to GroupBase.__getitem__ to raise an error on invalid higher dimensional inputs.

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

Developers certificate of origin


📚 Documentation preview 📚: https://mdanalysis--4656.org.readthedocs.build/en/4656/

@pep8speaks
Copy link

pep8speaks commented Aug 15, 2024

Hello @MattTDavies! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-08-21 16:33:21 UTC

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on GitHub Discussions so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS as part of this PR.

Copy link

github-actions bot commented Aug 15, 2024

Linter Bot Results:

Hi @MattTDavies! Thanks for making this PR. We linted your code and found the following:

Some issues were found with the formatting of your code.

Code Location Outcome
main package ⚠️ Possible failure
testsuite ⚠️ Possible failure

Please have a look at the darker-main-code and darker-test-code steps here for more details: https://github.com/MDAnalysis/mdanalysis/actions/runs/10493808829/job/29068636555


Please note: The black linter is purely informational, you can safely ignore these outcomes if there are no flake8 failures!

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.59%. Comparing base (f6a2c29) to head (9b83ae6).
Report is 41 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4656      +/-   ##
===========================================
- Coverage    93.61%   93.59%   -0.03%     
===========================================
  Files          171      185      +14     
  Lines        21254    22487    +1233     
  Branches      3937     3979      +42     
===========================================
+ Hits         19897    21046    +1149     
- Misses         898      977      +79     
- Partials       459      464       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Member

@richardjgowers richardjgowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I'm not sure we need the sanitization step

Comment on lines 603 to 609
if isinstance(item, np.ndarray) and item.ndim > 1:
item = np.squeeze(item)
# disallow high dimensional indexing.
# this doesnt stop the underlying issue
if item.ndim > 1:
raise IndexError('Group index must be 1d')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure (?) we have to allow ndim>1, so we can probably just raise an Error inside this branch without the np.squeeze step.

Is there a code path that currently uses the np.arange(5).reshape(-1, 1) route?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I can tell. The only tests that fail with the sanitisation removed are the newly added tests, to test the sanitisation is working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great then, I couldn't remember if something like Residue access was going via this route.

@richardjgowers richardjgowers self-assigned this Aug 21, 2024
@richardjgowers richardjgowers merged commit 326698d into MDAnalysis:develop Aug 22, 2024
17 of 23 checks passed
@MattTDavies MattTDavies deleted the atomgroup_indexing branch August 22, 2024 15:12
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.

GroupBase high dimensional indexing.
3 participants