Skip to content

Commit 27136a4

Browse files
committed
ENH: Use int64_error flag to raise ValueError
1 parent 886f020 commit 27136a4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

nibabel/nifti1.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from . import analyze # module import
2727
from .spm99analyze import SpmAnalyzeHeader
2828
from .casting import have_binary128
29+
from nibabel.__future__ import future_flags
2930

3031
pdcm, have_dicom, _ = optional_package("pydicom")
3132

@@ -1757,11 +1758,18 @@ def __init__(self, dataobj, affine, header=None,
17571758
extra=None, file_map=None, dtype=None):
17581759
danger_dts = (np.dtype("int64"), np.dtype("uint64"))
17591760
if header is None and dtype is None and dataobj.dtype in danger_dts:
1760-
msg = (f"Image data has type {dataobj.dtype}, which may cause "
1761-
"incompatibilities with other tools. This will error in "
1762-
"future versions of Nibabel. This warning can be silenced "
1763-
f"by passing the dtype argument to {self.__class__.__name__}().")
1764-
warnings.warn(msg, FutureWarning)
1761+
if future_flags['int64_error']:
1762+
raise ValueError(
1763+
f"Image data has type {dataobj.dtype}, which may cause "
1764+
"incompatibilities with other tools. To set an alternative "
1765+
f"on-disk dtype or force use of {dataobj.dtype}, pass a "
1766+
f"dtype argument to {self.__class__.__name__}().")
1767+
warnings.warn(
1768+
f"Image data has type {dataobj.dtype}, which may cause "
1769+
"incompatibilities with other tools. This will error in "
1770+
"future versions of Nibabel. This warning can be silenced "
1771+
f"by passing the dtype argument to {self.__class__.__name__}().",
1772+
FutureWarning)
17651773
super(Nifti1Pair, self).__init__(dataobj,
17661774
affine,
17671775
header,

0 commit comments

Comments
 (0)