@@ -898,26 +898,28 @@ 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
913+ but not supported
914+ >>> hdr.set_data_dtype('int')
914915 Traceback (most recent call last):
915916 ...
916917 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
918+ >>> hdr.set_data_dtype(int)
918919 Traceback (most recent call last):
919920 ...
920- ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
921+ ValueError: Invalid data type <class 'int'>. Specify a sized integer, e.g., 'uint8' or
922+ numpy.int16.
921923 >>> hdr.set_data_dtype('int64')
922924 >>> hdr.get_data_dtype() == np.dtype('int64')
923925 True
@@ -2057,7 +2059,7 @@ def set_data_dtype(self, datatype):
20572059 The following aliases are defined to allow for flexible specification:
20582060
20592061 * ``'mask'`` - Alias for ``uint8``
2060- * ``'compat'`` - The smallest Analyze-compatible datatype
2062+ * ``'compat'`` - The nearest Analyze-compatible datatype
20612063 (``uint8``, ``int16``, ``int32``, ``float32``)
20622064 * ``'smallest'`` - The smallest Analyze-compatible integer
20632065 (``uint8``, ``int16``, ``int32``)
@@ -2081,9 +2083,9 @@ def set_data_dtype(self, datatype):
20812083 >>> img.get_data_dtype()
20822084 'compat'
20832085 >>> img.get_data_dtype(finalize=True)
2084- dtype('uint8 ')
2086+ dtype('<i4 ')
20852087 >>> img.get_data_dtype()
2086- dtype('uint8 ')
2088+ dtype('<i4 ')
20872089 >>> img.set_data_dtype('smallest')
20882090 >>> img.get_data_dtype()
20892091 'smallest'
@@ -2095,31 +2097,39 @@ def set_data_dtype(self, datatype):
20952097 Note that floating point values will not be coerced to ``int``
20962098
20972099 >>> floats = np.arange(24, dtype='f4').reshape((2,3,4))
2098- >>> img = Nifti1Image(ints, np.eye(4))
2100+ >>> img = Nifti1Image(floats, np.eye(4))
2101+ >>> img.set_data_dtype('smallest')
2102+ >>> img.get_data_dtype(finalize=True)
2103+ Traceback (most recent call last):
2104+ ...
2105+ ValueError: Cannot automatically cast array (of type float32) to an integer
2106+ type with fewer than 64 bits. Please set_data_dtype() to an explicit data type.
20992107
21002108 >>> arr = np.arange(1000, 1024, dtype='i4').reshape((2,3,4))
21012109 >>> img = Nifti1Image(arr, np.eye(4))
21022110 >>> img.set_data_dtype('smallest')
2103- >>> img.set_data_dtype('implausible') #doctest: +IGNORE_EXCEPTION_DETAIL
2111+ >>> img.set_data_dtype('implausible')
21042112 Traceback (most recent call last):
21052113 ...
2106- HeaderDataError: data dtype "implausible" not recognized
2107- >>> img.set_data_dtype('none') #doctest: +IGNORE_EXCEPTION_DETAIL
2114+ nibabel.spatialimages. HeaderDataError: data dtype "implausible" not recognized
2115+ >>> img.set_data_dtype('none')
21082116 Traceback (most recent call last):
21092117 ...
2110- HeaderDataError: data dtype "none" known but not supported
2111- >>> img.set_data_dtype(np.void) #doctest: +IGNORE_EXCEPTION_DETAIL
2118+ nibabel.spatialimages. HeaderDataError: data dtype "none" known but not supported
2119+ >>> img.set_data_dtype(np.void)
21122120 Traceback (most recent call last):
21132121 ...
2114- HeaderDataError: data dtype "<type 'numpy.void'>" known but not supported
2115- >>> img.set_data_dtype('int') #doctest: +IGNORE_EXCEPTION_DETAIL
2122+ nibabel.spatialimages.HeaderDataError: data dtype "<class 'numpy.void'>" known
2123+ but not supported
2124+ >>> img.set_data_dtype('int')
21162125 Traceback (most recent call last):
21172126 ...
21182127 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
2128+ >>> img.set_data_dtype(int)
21202129 Traceback (most recent call last):
21212130 ...
2122- ValueError: Invalid data type 'int'. Specify a sized integer, e.g., 'uint8' or numpy.int16.
2131+ ValueError: Invalid data type <class 'int'>. Specify a sized integer, e.g., 'uint8' or
2132+ numpy.int16.
21232133 >>> img.set_data_dtype('int64')
21242134 >>> img.get_data_dtype() == np.dtype('int64')
21252135 True
0 commit comments