Skip to content

Commit db2f327

Browse files
committed
DOC: Update doctests with correct outputs
1 parent 94e3d1d commit db2f327

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

nibabel/nifti1.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -898,26 +898,26 @@ def set_data_dtype(self, datatype):
898898
>>> hdr.set_data_dtype(np.dtype(np.uint8))
899899
>>> hdr.get_data_dtype()
900900
dtype('uint8')
901-
>>> hdr.set_data_dtype('implausible') #doctest: +IGNORE_EXCEPTION_DETAIL
901+
>>> hdr.set_data_dtype('implausible')
902902
Traceback (most recent call last):
903903
...
904-
HeaderDataError: data dtype "implausible" not recognized
905-
>>> hdr.set_data_dtype('none') #doctest: +IGNORE_EXCEPTION_DETAIL
904+
nibabel.spatialimages.HeaderDataError: data dtype "implausible" not recognized
905+
>>> hdr.set_data_dtype('none')
906906
Traceback (most recent call last):
907907
...
908-
HeaderDataError: data dtype "none" known but not supported
909-
>>> hdr.set_data_dtype(np.void) #doctest: +IGNORE_EXCEPTION_DETAIL
908+
nibabel.spatialimages.HeaderDataError: data dtype "none" known but not supported
909+
>>> hdr.set_data_dtype(np.void)
910910
Traceback (most recent call last):
911911
...
912-
HeaderDataError: data dtype "<type 'numpy.void'>" known but not supported
913-
>>> hdr.set_data_dtype('int') #doctest: +IGNORE_EXCEPTION_DETAIL
912+
nibabel.spatialimages.HeaderDataError: data dtype "<class 'numpy.void'>" known but not supported
913+
>>> hdr.set_data_dtype('int')
914914
Traceback (most recent call last):
915915
...
916916
ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
917-
>>> hdr.set_data_dtype(int) #doctest: +IGNORE_EXCEPTION_DETAIL
917+
>>> hdr.set_data_dtype(int)
918918
Traceback (most recent call last):
919919
...
920-
ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
920+
ValueError: Invalid data type <class 'int'>. Specify a sized integer, e.g., 'uint8' or numpy.int16.
921921
>>> hdr.set_data_dtype('int64')
922922
>>> hdr.get_data_dtype() == np.dtype('int64')
923923
True
@@ -2057,7 +2057,7 @@ def set_data_dtype(self, datatype):
20572057
The following aliases are defined to allow for flexible specification:
20582058
20592059
* ``'mask'`` - Alias for ``uint8``
2060-
* ``'compat'`` - The smallest Analyze-compatible datatype
2060+
* ``'compat'`` - The nearest Analyze-compatible datatype
20612061
(``uint8``, ``int16``, ``int32``, ``float32``)
20622062
* ``'smallest'`` - The smallest Analyze-compatible integer
20632063
(``uint8``, ``int16``, ``int32``)
@@ -2081,9 +2081,9 @@ def set_data_dtype(self, datatype):
20812081
>>> img.get_data_dtype()
20822082
'compat'
20832083
>>> img.get_data_dtype(finalize=True)
2084-
dtype('uint8')
2084+
dtype('<i4')
20852085
>>> img.get_data_dtype()
2086-
dtype('uint8')
2086+
dtype('<i4')
20872087
>>> img.set_data_dtype('smallest')
20882088
>>> img.get_data_dtype()
20892089
'smallest'
@@ -2095,31 +2095,37 @@ def set_data_dtype(self, datatype):
20952095
Note that floating point values will not be coerced to ``int``
20962096
20972097
>>> floats = np.arange(24, dtype='f4').reshape((2,3,4))
2098-
>>> img = Nifti1Image(ints, np.eye(4))
2098+
>>> img = Nifti1Image(floats, np.eye(4))
2099+
>>> img.set_data_dtype('smallest')
2100+
>>> img.get_data_dtype(finalize=True)
2101+
Traceback (most recent call last):
2102+
...
2103+
ValueError: Cannot automatically cast array (of type float32) to an integer
2104+
type with fewer than 64 bits. Please set_data_dtype() to an explicit data type.
20992105
21002106
>>> arr = np.arange(1000, 1024, dtype='i4').reshape((2,3,4))
21012107
>>> img = Nifti1Image(arr, np.eye(4))
21022108
>>> img.set_data_dtype('smallest')
2103-
>>> img.set_data_dtype('implausible') #doctest: +IGNORE_EXCEPTION_DETAIL
2109+
>>> img.set_data_dtype('implausible')
21042110
Traceback (most recent call last):
21052111
...
2106-
HeaderDataError: data dtype "implausible" not recognized
2107-
>>> img.set_data_dtype('none') #doctest: +IGNORE_EXCEPTION_DETAIL
2112+
nibabel.spatialimages.HeaderDataError: data dtype "implausible" not recognized
2113+
>>> img.set_data_dtype('none')
21082114
Traceback (most recent call last):
21092115
...
2110-
HeaderDataError: data dtype "none" known but not supported
2111-
>>> img.set_data_dtype(np.void) #doctest: +IGNORE_EXCEPTION_DETAIL
2116+
nibabel.spatialimages.HeaderDataError: data dtype "none" known but not supported
2117+
>>> img.set_data_dtype(np.void)
21122118
Traceback (most recent call last):
21132119
...
2114-
HeaderDataError: data dtype "<type 'numpy.void'>" known but not supported
2115-
>>> img.set_data_dtype('int') #doctest: +IGNORE_EXCEPTION_DETAIL
2120+
nibabel.spatialimages.HeaderDataError: data dtype "<class 'numpy.void'>" known but not supported
2121+
>>> img.set_data_dtype('int')
21162122
Traceback (most recent call last):
21172123
...
21182124
ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
2119-
>>> img.set_data_dtype(int) #doctest: +IGNORE_EXCEPTION_DETAIL
2125+
>>> img.set_data_dtype(int)
21202126
Traceback (most recent call last):
21212127
...
2122-
ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
2128+
ValueError: Invalid data type <class 'int'>. Specify a sized integer, e.g., 'uint8' or numpy.int16.
21232129
>>> img.set_data_dtype('int64')
21242130
>>> img.get_data_dtype() == np.dtype('int64')
21252131
True

0 commit comments

Comments
 (0)