Skip to content

Commit 8a92010

Browse files
committed
very inefficient but successfully removed dtype when its identical
1 parent bb3fbf0 commit 8a92010

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

nibabel/cmdline/diff.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,30 @@ def diff_header_fields(key, inputs):
7878
keyed_inputs = []
7979

8080
for i in inputs: # stores each file's respective header files
81+
field_value = i[key]
8182

8283
try:
83-
if np.all(np.isnan(i[key])):
84+
if np.all(np.isnan(field_value)):
8485
continue
8586
except TypeError:
8687
pass
8788

88-
if i[key].ndim < 1:
89-
keyed_inputs.append("{}@{}".format(i[key], i[key].dtype))
90-
elif i[key].ndim == 1:
91-
keyed_inputs.append("{}@{}".format(list(i[key]), i[key].dtype))
89+
for x in inputs[1:]:
90+
data_diff = diff_values(str(x[key].dtype), str(field_value.dtype))
91+
92+
if data_diff:
93+
break
94+
95+
if data_diff:
96+
if field_value.ndim < 1:
97+
keyed_inputs.append("{}@{}".format(field_value, field_value.dtype))
98+
elif field_value.ndim == 1:
99+
keyed_inputs.append("{}@{}".format(list(field_value), field_value.dtype))
92100
else:
93-
pass
101+
if field_value.ndim < 1:
102+
keyed_inputs.append("{}".format(field_value))
103+
elif field_value.ndim == 1:
104+
keyed_inputs.append("{}".format(list(field_value)))
94105

95106
if keyed_inputs: # sometimes keyed_inputs is empty lol
96107
comparison_input = keyed_inputs[0]
@@ -139,8 +150,7 @@ def main():
139150

140151
diff = get_headers_diff(files, opts)
141152

142-
if opts.text:
143-
153+
if opts.text: # using string formatting to print a table of the results
144154
print("{:<11}".format('Field'), end="", flush=True)
145155

146156
for f in files:

0 commit comments

Comments
 (0)