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
[MAINT] Format nilearn/plotting: apply isort and fix flake8 errors #3648
Conversation
👋 @Remi-Gau Thanks for creating a PR! Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft. Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.
For new features:
For bug fixes:
We will review it as quick as possible, feel free to ping us with questions if needed. |
Codecov Report
@@ Coverage Diff @@
## main #3648 +/- ##
==========================================
- Coverage 91.57% 91.56% -0.01%
==========================================
Files 139 139
Lines 16576 16566 -10
Branches 3233 3233
==========================================
- Hits 15179 15169 -10
Misses 1394 1394
Partials 3 3
... and 9 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments. I haven't reviewed the tests yet.
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of thoughts:
- The new plotting fixtures seem to be specific to the plotting module while the other fixtures are a bit more general, perhaps they can stay in the plotting module
- Can any "create fake data" function from _utils.data_gen be reused to create these fixtures? Or we can specify new functions in data_gen and then specify the fixtures here (or under plotting) if we see that they can be useful in other modules/fixtures
These are maybe for another PR but I also think that moving the fixtures would be better done under a refactoring PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW to add locations of fixtures for pytest to find you can add the following code to conftest.py
:
pytest_plugins = [
"nilearn.plotting.tests.test_img_plotting.testing_utils",
]
And then change the names of the fixtures and then you don't have to undo the changes in the files that use those fixtures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only moved the fixtures. I started seeing ways to improve them but refactoring that is beyond the scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ymzayek
are you reading this failure of the tests on python 3.7 without matplotlib the same way I am?
+ python -m pytest --pyargs nilearn --cov=nilearn
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.7.16/x64/lib/python3.7/site-packages/_pytest/config/__init__.py", line 774, in import_plugin
__import__(importspec)
File "/home/runner/work/nilearn/nilearn/nilearn/plotting/__init__.py", line 53, in <module>
_set_mpl_backend()
File "/home/runner/work/nilearn/nilearn/nilearn/plotting/__init__.py", line 14, in _set_mpl_backend
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
see the rest here:
https://github.com/nilearn/nilearn/actions/runs/4787578339/jobs/8512995221?pr=3648#step:7:92
It seems that when trying to use the plugin fixtures that we have now moved to be specific to the plotting we now get an matplotlib import error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Remi-Gau regarding the last few lines of the trace back of that link:
File "/home/runner/work/nilearn/nilearn/nilearn/plotting/__init__.py", line 53, in <module>
_set_mpl_backend()
File "/home/runner/work/nilearn/nilearn/nilearn/plotting/__init__.py", line 14, in _set_mpl_backend
import matplotlib
ImportError: Error importing plugin "nilearn.plotting.tests.test_img_plotting._utils": No module named 'matplotlib'
What was in nilearn.plotting.tests.test_img_plotting._utils
exactly?
Maybe there was an import of matplotlib that wasn't being flagged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing you can try is to keep the name testing_utils.py
. I'm wondering if it was named as such because of something specific to how pytest handles filenames. Just making guesses here. Feel free to transfer this discussion to a new issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was in
nilearn.plotting.tests.test_img_plotting._utils
exactly?
See here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing you can try is to keep the name
testing_utils.py
.
that did not work either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the nature of the fixtures that were moved in conftest.py I think that they can be renamed, refactored to be more reusable in other tests.
This will hopefully become more obvious as we keep refactoring the test suite in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @Remi-Gau !
TODO
|
"img_mask": img_mask, | ||
"img_atlas": img_atlas, | ||
"atlas_labels": atlas_labels, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ymzayek
Only I have found to make the test without matplotlib pass, is to keep those fixture outside of the nilearn plotting package.
I suspect this could be improved / fixed but for now I would suggest to keep those here and address the location of those fixtures when refactoring the tests for plotting.
There definitely is a flaky test:
|
This will be merged after the next release #3724 |
Relates to #2528
Changes proposed in this pull request: