Skip to content

Commit d61ea07

Browse files
committed
TYP: Annotate DataobjImage classmethods, clarify get_fdata() return type
1 parent 2e1814c commit d61ea07

File tree

8 files changed

+15
-13
lines changed

8 files changed

+15
-13
lines changed

nibabel/analyze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,5 +1064,5 @@ def to_file_map(self, file_map=None, dtype=None):
10641064
hdr['scl_inter'] = inter
10651065

10661066

1067-
load = AnalyzeImage.load
1067+
load = AnalyzeImage.from_filename
10681068
save = AnalyzeImage.instance_to_filename

nibabel/brikhead.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,4 @@ def filespec_to_file_map(klass, filespec):
564564
return file_map
565565

566566

567-
load = AFNIImage.load
567+
load = AFNIImage.from_filename

nibabel/dataobj_images.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
if ty.TYPE_CHECKING: # pragma: no cover
2121
import numpy.typing as npt
2222

23+
ArrayImgT = ty.TypeVar('ArrayImgT', bound='DataobjImage')
24+
2325

2426
class DataobjImage(FileBasedImage):
2527
"""Template class for images that have dataobj data stores"""
2628

2729
_data_cache: np.ndarray | None
28-
_fdata_cache: np.ndarray | None
30+
_fdata_cache: np.ndarray[ty.Any, np.dtype[np.floating]] | None
2931

3032
def __init__(
3133
self,
@@ -222,7 +224,7 @@ def get_fdata(
222224
self,
223225
caching: ty.Literal['fill', 'unchanged'] = 'fill',
224226
dtype: npt.DTypeLike = np.float64,
225-
) -> np.ndarray:
227+
) -> np.ndarray[ty.Any, np.dtype[np.floating]]:
226228
"""Return floating point image data with necessary scaling applied
227229
228230
The image ``dataobj`` property can be an array proxy or an array. An
@@ -421,12 +423,12 @@ def ndim(self) -> int:
421423

422424
@classmethod
423425
def from_file_map(
424-
klass,
426+
klass: type[ArrayImgT],
425427
file_map: FileMap,
426428
*,
427429
mmap: bool | ty.Literal['c', 'r'] = True,
428430
keep_file_open: bool | None = None,
429-
):
431+
) -> ArrayImgT:
430432
"""Class method to create image from mapping in ``file_map``
431433
432434
Parameters
@@ -460,12 +462,12 @@ def from_file_map(
460462

461463
@classmethod
462464
def from_filename(
463-
klass,
465+
klass: type[ArrayImgT],
464466
filename: FileSpec,
465467
*,
466468
mmap: bool | ty.Literal['c', 'r'] = True,
467469
keep_file_open: bool | None = None,
468-
):
470+
) -> ArrayImgT:
469471
"""Class method to create image from filename `filename`
470472
471473
Parameters

nibabel/freesurfer/mghformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,5 +589,5 @@ def _affine2header(self):
589589
hdr['Pxyz_c'] = c_ras
590590

591591

592-
load = MGHImage.load
592+
load = MGHImage.from_filename
593593
save = MGHImage.instance_to_filename

nibabel/minc1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,4 @@ def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
334334
return klass(data, affine, header, extra=None, file_map=file_map)
335335

336336

337-
load = Minc1Image.load
337+
load = Minc1Image.from_filename

nibabel/minc2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
172172
return klass(data, affine, header, extra=None, file_map=file_map)
173173

174174

175-
load = Minc2Image.load
175+
load = Minc2Image.from_filename

nibabel/spm2analyze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,5 @@ class Spm2AnalyzeImage(spm99.Spm99AnalyzeImage):
130130
header_class = Spm2AnalyzeHeader
131131

132132

133-
load = Spm2AnalyzeImage.load
133+
load = Spm2AnalyzeImage.from_filename
134134
save = Spm2AnalyzeImage.instance_to_filename

nibabel/spm99analyze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,5 @@ def to_file_map(self, file_map=None, dtype=None):
331331
sio.savemat(mfobj, {'M': M, 'mat': mat}, format='4')
332332

333333

334-
load = Spm99AnalyzeImage.load
334+
load = Spm99AnalyzeImage.from_filename
335335
save = Spm99AnalyzeImage.instance_to_filename

0 commit comments

Comments
 (0)