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] Fix pathlib.Path not being counted as Niimg-like in new_image_like #3723
Conversation
👋 @mcsitter 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 #3723 +/- ##
=======================================
Coverage 91.53% 91.53%
=======================================
Files 134 134
Lines 15751 15753 +2
Branches 3281 3281
=======================================
+ Hits 14418 14420 +2
Misses 784 784
Partials 549 549
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 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.
Thanks for contributing @mcsitter
I might be missing something, but you should be able to provide a Path
object to these functions. The path object is first casted to a string by stringify_path
:
>>> stringify_path(Path("./foo.json"))
'foo.json'
@mcsitter could you provide a reproducible example that will fail if we run it? As @NicolasGensollen pointed out, this case is supposed to be handled by |
@ymzayek I am on nilearn version 0.10.0. Here is some could which should allow you to reproduce the TypeError: import pathlib
import nilearn.image
from nilearn.datasets import MNI152_FILE_PATH
image_path = pathlib.Path(MNI152_FILE_PATH)
image = nilearn.image.load_img(image_path)
nilearn.image.new_img_like(image_path, image.get_fdata()) |
@mcsitter ok I see, indeed |
@ymzayek I changed the code to use |
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 ! We should add the corresponding unit test to enforce this behavior. Can you do that ?
@mcsitter can you define a test under |
@mcsitter are you able to pick this back up and finish it? Otherwise, I can take it over and make the necessary changes. |
I am not sure I did the rebasing correctly... But I added a unit test, hopefully, a useful one, and added my name to the Feel free to let me know if there is anything else I can do or how I would fix any mishaps regarding the rebasing. |
Given the number of line and file changes I would say that something looks not right. Am AFK at the moment but I will have a look when on a screen that is more than 20 characters wide. |
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.
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.
yup it looks good to me
Oops let me fix the flake8 error |
data = np.random.rand(10, 10, 10) | ||
img = Nifti1Image(data, np.eye(4)) |
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.
not needed for now but I think there may be a lot random img creation in the whole test suite that could be fixturised
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.
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! Merging.
Failure is unrelated (also failing on main)
I received
TypeError: The reference image should be a niimg
when putting apathlib.Path
as an argument intonilearn.image.new_image_like
. I fixed it to properly accept Niimg-like objects, which includepathlib.Path
in its definition.Changes proposed in this pull request:
isinstance
ofpathlib.Path
as well asstr