Skip to content

Fix get_basic_statistics() path type check#560

Merged
wasserth merged 1 commit intowasserth:masterfrom
mhalle:fix/get-basic-statistics-path-type
Mar 30, 2026
Merged

Fix get_basic_statistics() path type check#560
wasserth merged 1 commit intowasserth:masterfrom
mhalle:fix/get-basic-statistics-path-type

Conversation

@mhalle
Copy link
Copy Markdown
Contributor

@mhalle mhalle commented Mar 24, 2026

Summary

  • get_basic_statistics() used type(ct_file) == pathlib.PosixPath to decide whether to load from disk. This exact type check fails for string paths, WindowsPath, and other PathLike inputs — they fall through to the else branch which treats them as a Nifti1Image, causing an AttributeError on .get_fdata().
  • Fix: use isinstance(ct_file, (str, Path)) to match all common path types. Path covers both PosixPath and WindowsPath, and str covers plain string paths.

Test plan

  • Call get_basic_statistics() with a string path and verify it loads correctly
  • Call with a Path object and verify it loads correctly
  • Call with a Nifti1Image object and verify it uses the object directly

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>
@wasserth wasserth merged commit 93c72c0 into wasserth:master Mar 30, 2026
2 checks passed
@mhalle mhalle deleted the fix/get-basic-statistics-path-type branch April 3, 2026 00:47
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.

2 participants