Fix get_basic_statistics() path type check#560
Merged
wasserth merged 1 commit intowasserth:masterfrom Mar 30, 2026
Merged
Conversation
The check `type(ct_file) == pathlib.PosixPath` only matched PosixPath exactly, so string paths, WindowsPath, and other PathLike inputs would skip nib.load() and be passed directly to get_fdata(), causing an AttributeError. Use isinstance() with (str, Path) to handle all common path types. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_basic_statistics()usedtype(ct_file) == pathlib.PosixPathto decide whether to load from disk. This exact type check fails for string paths,WindowsPath, and otherPathLikeinputs — they fall through to theelsebranch which treats them as a Nifti1Image, causing anAttributeErroron.get_fdata().isinstance(ct_file, (str, Path))to match all common path types.Pathcovers bothPosixPathandWindowsPath, andstrcovers plain string paths.Test plan
get_basic_statistics()with a string path and verify it loads correctlyPathobject and verify it loads correctlyNifti1Imageobject and verify it uses the object directly