Skip to content

Commit 22fe8c2

Browse files
committed
Merge remote-tracking branch 'upstream/maint/2.5.x'
2 parents 05dd2cd + 8d68c7f commit 22fe8c2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

nibabel/cmdline/diff.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
1010
"""
1111
Quick summary of the differences among a set of neuroimaging files
12+
13+
Notes:
14+
- difference in data types for header fields will be detected, but
15+
endianness difference will not be detected. It is done so to compare files
16+
with native endianness used in data files.
1217
"""
1318

1419
import re
@@ -98,7 +103,8 @@ def are_values_different(*values):
98103
if type(value0) != type(value): # if types are different, then we consider them different
99104
return True
100105
elif isinstance(value0, np.ndarray):
101-
if value0.dtype != value.dtype or \
106+
# use .dtype.type to provide endianness agnostic comparison
107+
if value0.dtype.type != value.dtype.type or \
102108
value0.shape != value.shape:
103109
return True
104110
# there might be nans and they need special treatment

nibabel/tests/test_diff.py

+6
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,9 @@ def test_diff_values_array():
7171
# and some inf should not be a problem
7272
assert not are_values_different(array([0, inf]), array([0, inf]))
7373
assert are_values_different(array([0, inf]), array([inf, 0]))
74+
75+
# we will allow for types to be of different endianness but the
76+
# same in "instnatiation" type and value
77+
assert not are_values_different(np.array(1, dtype='<i4'), np.array(1, dtype='>i4'))
78+
# but do report difference if instantiation type is different:
79+
assert are_values_different(np.array(1, dtype='<i4'), np.array(1, dtype='<i2'))

0 commit comments

Comments
 (0)