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

Fix for issue #4655 Removing mutable data structures and function calls as default arguments in the entire codebase #4810

Closed
wants to merge 7 commits into from

Conversation

tanishy7777
Copy link
Contributor

@tanishy7777 tanishy7777 commented Nov 30, 2024

Fixes #4655

Changes made in this Pull Request:

  • Removing mutable data structures and function calls as default arguments in the entire codebase and initializing/calling them inside the function instead
  • There were 12 issues found using the ruff module(select = B006, B008 and ignore=E501) which were all fixed

PR Checklist

  • Tests
  • CHANGELOG updated?
  • Issue raised/referenced

Developers certificate of origin


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

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.

@tanishy7777
Copy link
Contributor Author

Before and after the changes were made (results below are from pytest tests in the testsuite)
Before
image

After the changes
image

Copy link

codecov bot commented Nov 30, 2024

Codecov Report

Attention: Patch coverage is 64.28571% with 10 lines in your changes missing coverage. Please review.

Project coverage is 93.62%. Comparing base (a27591c) to head (1c1c644).

Files with missing lines Patch % Lines
package/MDAnalysis/analysis/encore/similarity.py 62.50% 0 Missing and 3 partials ⚠️
package/MDAnalysis/analysis/base.py 0.00% 1 Missing and 1 partial ⚠️
package/MDAnalysis/analysis/helix_analysis.py 66.66% 1 Missing and 1 partial ⚠️
package/MDAnalysis/topology/ITPParser.py 33.33% 1 Missing and 1 partial ⚠️
package/MDAnalysis/analysis/align.py 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4810      +/-   ##
===========================================
- Coverage    93.68%   93.62%   -0.07%     
===========================================
  Files          177      189      +12     
  Lines        21743    22833    +1090     
  Branches      3055     3067      +12     
===========================================
+ Hits         20370    21377    +1007     
- Misses         927     1003      +76     
- Partials       446      453       +7     

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

Copy link
Member

@RMeli RMeli left a comment

Choose a reason for hiding this comment

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

Can you please detail how the error raised in #4810 (comment) is related to the changes?

package/CHANGELOG Outdated Show resolved Hide resolved
package/CHANGELOG Outdated Show resolved Hide resolved
@@ -387,11 +388,13 @@ class HELANAL(AnalysisBase):
'local_screw_angles': (-2,),
}

def __init__(self, universe, select='name CA', ref_axis=[0, 0, 1],
def __init__(self, universe, select='name CA', ref_axis=None,
Copy link
Member

Choose a reason for hiding this comment

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

What about using a tuple instead of a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I can do that

Copy link
Member

Choose a reason for hiding this comment

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

I meant using it as an argument (instead of adding the logic with None). Because tuples are immutable (while lists are mutable).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant using it as an argument (instead of adding the logic with None). Because tuples are immutable (while lists are mutable).

Oh that makes sense

@tanishy7777
Copy link
Contributor Author

tanishy7777 commented Dec 1, 2024

Can you please detail how the error raised in #4810 (comment) is related to the changes?

I am not sure why the error got resolved, but after making the changes it got solved.

According to the file test_encore from which the error was generated from, the function can result in failure sometimes because the function involves generating random numbers.

image

shortened the fixes in the changelog
using tuples instead of list for ref_axis
@tanishy7777
Copy link
Contributor Author

I have added the changes that you have mentioned @RMeli

Copy link
Member

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

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

I'm "ok" with the diff modulo one or two outstanding comments from Rocco.

Any chance folks would be on board to "enforce" this in CI with ruff check package --select B006,B008? ruff is pretty fast and widely adopted now, and that would only check for these two rules and nothing else. Eventually using a ruff.toml might make sense, but maybe one step at a time...

@tylerjereddy
Copy link
Member

The CI fails are all unrelated--the usual rdkit failure observed in other recent PRs.

@RMeli
Copy link
Member

RMeli commented Dec 7, 2024

Any chance folks would be on board to "enforce" this in CI with ruff check package --select B006,B008? ruff is pretty fast and widely adopted now, and that would only check for these two rules and nothing else. Eventually using a ruff.toml might make sense, but maybe one step at a time...

+1 for adding ruff with these rules. We went with black for formatting, but I think it would be good to have ruff for linting since it has some momentum. I can add it to the GitHub action limited to the few rules you suggest, then we can expand it with time and when formatting is over (addressing the listing issues not concerning formatting was the next step anyways).

@tanishy7777 tanishy7777 closed this by deleting the head repository Dec 12, 2024
@RMeli
Copy link
Member

RMeli commented Dec 12, 2024

@tanishy7777 Why did you close this PR? Besides #4810 (comment) I think it was in a pretty good shape.

@tanishy7777
Copy link
Contributor Author

tanishy7777 commented Dec 12, 2024

@RMeli I am really sorry I was trying to creating a new fork, and deleted the old one. I think that may have closed the PR

@RMeli
Copy link
Member

RMeli commented Dec 13, 2024

No worries @tanishy7777, that happens. Are you going to re-open the PR from the new fork? I think it was almost ready to be merged, so it would be good to have. But if you don't want to work on it anymore, no worries at all.

@tanishy7777
Copy link
Contributor Author

No worries @tanishy7777, that happens. Are you going to re-open the PR from the new fork? I think it was almost ready to be merged, so it would be good to have. But if you don't want to work on it anymore, no worries at all.

Thanks for understanding. I will open the new PR from the new fork. I plan to just make all the changes locally on my pc again and then push that in the PR. I don't think there is a better way right? Since I deleted the old repo? @RMeli

@tanishy7777
Copy link
Contributor Author

tanishy7777 commented Dec 13, 2024

Also just to clarify the reason u merged develop onto my commit is because I think I might have created a new branch using

git checkout -b <new-branch-name>

instead of

git checkout -b <new-branch-name> develop

Which also explains why the codecov percentage was so different? Is that right?

@RMeli
Copy link
Member

RMeli commented Dec 13, 2024

@tanishy7777 I merged develop in this PR because #4640 fixed some issues with the tests, and therefore was needed to fix the tests running for this PR. With git pull you would have got the changes on your local repository as well. Sorry for the confusion.

I don't think there is a better way right?

Unfortunately, I don't think so. If you can't be bothered no worries, I can fix these issues myself if we decide to go ahead with #4825. Up to you if you want to spend more time on this.

@tanishy7777
Copy link
Contributor Author

tanishy7777 commented Dec 13, 2024

@tanishy7777 I merged develop in this PR because #4640 fixed some issues with the tests, and therefore was needed to fix the tests running for this PR. With git pull you would have got the changes on your local repository as well. Sorry for the confusion.

Oh ok got it!

Unfortunately, I don't think so. If you can't be bothered no worries, I can fix these issues myself if we decide to go ahead with #4825. Up to you if you want to spend more time on this.

No problems! I have made the new PR in #4834
@RMeli

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

Successfully merging this pull request may close these issues.

MAINT: a few mutable default arguments are back
3 participants