Skip to content

Commit 1a9ebad

Browse files
author
Mathieu Scheltienne
committed
fix more stuff
1 parent c60a234 commit 1a9ebad

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

nibabel/ecat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ def _write_data(self, data, stream, pos, dtype=None, endianness=None):
923923
endianness = native_code
924924

925925
stream.seek(pos)
926-
make_array_writer(data.newbyteorder(endianness), dtype).to_fileobj(stream)
926+
make_array_writer(data.view(data.dtype.newbyteorder(endianness)), dtype).to_fileobj(stream)
927927

928928
def to_file_map(self, file_map=None):
929929
"""Write ECAT7 image to `file_map` or contained ``self.file_map``

nibabel/freesurfer/tests/test_io.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ def test_geometry():
111111
assert np.array_equal(faces, faces2)
112112

113113
# Validate byte ordering
114-
coords_swapped = coords.byteswap().newbyteorder()
115-
faces_swapped = faces.byteswap().newbyteorder()
114+
coords_swapped = coords.byteswap()
115+
coords_swapped = coords_swapped.view(coords_swapped.dtype.newbyteorder())
116+
faces_swapped = faces.byteswap()
117+
faces_swapped = faces_swapped.view(faces_swapped.dtype.newbyteorder())
116118
assert np.array_equal(coords_swapped, coords)
117119
assert np.array_equal(faces_swapped, faces)
118120

nibabel/nifti1.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,9 +2443,13 @@ def _get_analyze_compat_dtype(arr):
24432443
return np.dtype('int16' if arr.max() <= np.iinfo(np.int16).max else 'int32')
24442444

24452445
mn, mx = arr.min(), arr.max()
2446-
if np.can_cast(mn, np.int32) and np.can_cast(mx, np.int32):
2446+
if (isinstance(mn, int) and isinstance(mx, int)) or (
2447+
np.can_cast(mn, np.int32) and np.can_cast(mx, np.int32)
2448+
):
24472449
return np.dtype('int32')
2448-
if np.can_cast(mn, np.float32) and np.can_cast(mx, np.float32):
2450+
if (isinstance(mn, float) and isinstance(mx, float)) or (
2451+
np.can_cast(mn, np.float32) and np.can_cast(mx, np.float32)
2452+
):
24492453
return np.dtype('float32')
24502454

24512455
raise ValueError(

0 commit comments

Comments
 (0)