@@ -898,26 +898,26 @@ def set_data_dtype(self, datatype):
898
898
>>> hdr.set_data_dtype(np.dtype(np.uint8))
899
899
>>> hdr.get_data_dtype()
900
900
dtype('uint8')
901
- >>> hdr.set_data_dtype('implausible') #doctest: +IGNORE_EXCEPTION_DETAIL
901
+ >>> hdr.set_data_dtype('implausible')
902
902
Traceback (most recent call last):
903
903
...
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')
906
906
Traceback (most recent call last):
907
907
...
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)
910
910
Traceback (most recent call last):
911
911
...
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')
914
914
Traceback (most recent call last):
915
915
...
916
916
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)
918
918
Traceback (most recent call last):
919
919
...
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.
921
921
>>> hdr.set_data_dtype('int64')
922
922
>>> hdr.get_data_dtype() == np.dtype('int64')
923
923
True
@@ -2057,7 +2057,7 @@ def set_data_dtype(self, datatype):
2057
2057
The following aliases are defined to allow for flexible specification:
2058
2058
2059
2059
* ``'mask'`` - Alias for ``uint8``
2060
- * ``'compat'`` - The smallest Analyze-compatible datatype
2060
+ * ``'compat'`` - The nearest Analyze-compatible datatype
2061
2061
(``uint8``, ``int16``, ``int32``, ``float32``)
2062
2062
* ``'smallest'`` - The smallest Analyze-compatible integer
2063
2063
(``uint8``, ``int16``, ``int32``)
@@ -2081,9 +2081,9 @@ def set_data_dtype(self, datatype):
2081
2081
>>> img.get_data_dtype()
2082
2082
'compat'
2083
2083
>>> img.get_data_dtype(finalize=True)
2084
- dtype('uint8 ')
2084
+ dtype('<i4 ')
2085
2085
>>> img.get_data_dtype()
2086
- dtype('uint8 ')
2086
+ dtype('<i4 ')
2087
2087
>>> img.set_data_dtype('smallest')
2088
2088
>>> img.get_data_dtype()
2089
2089
'smallest'
@@ -2095,31 +2095,37 @@ def set_data_dtype(self, datatype):
2095
2095
Note that floating point values will not be coerced to ``int``
2096
2096
2097
2097
>>> 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.
2099
2105
2100
2106
>>> arr = np.arange(1000, 1024, dtype='i4').reshape((2,3,4))
2101
2107
>>> img = Nifti1Image(arr, np.eye(4))
2102
2108
>>> img.set_data_dtype('smallest')
2103
- >>> img.set_data_dtype('implausible') #doctest: +IGNORE_EXCEPTION_DETAIL
2109
+ >>> img.set_data_dtype('implausible')
2104
2110
Traceback (most recent call last):
2105
2111
...
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')
2108
2114
Traceback (most recent call last):
2109
2115
...
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)
2112
2118
Traceback (most recent call last):
2113
2119
...
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')
2116
2122
Traceback (most recent call last):
2117
2123
...
2118
2124
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)
2120
2126
Traceback (most recent call last):
2121
2127
...
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.
2123
2129
>>> img.set_data_dtype('int64')
2124
2130
>>> img.get_data_dtype() == np.dtype('int64')
2125
2131
True
0 commit comments