Skip to content

Commit b956a26

Browse files
committed
ENH: drop use of Counter in favor of MB's shared snippet using recipe from scipy
+ adjusted the test which for some reason has failed on me although I don't think I have done any related changes here
1 parent f29cf62 commit b956a26

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

bin/nib-ls

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import sys
2222
from math import ceil
2323
from optparse import OptionParser, Option
2424
from io import StringIO
25-
from collections import Counter
2625

2726
import numpy as np
2827

@@ -231,10 +230,9 @@ def proc_file(f, opts):
231230
# stats
232231
row += [len(d) and '@l[%.2g, %.2g]' % (np.min(d), np.max(d)) or '-']
233232
if opts.counts:
234-
counter = Counter()
235-
counter.update(d.flatten())
236-
# go through each entry and report only non-0 ones
237-
row += ["@l" + " ".join("%g:%d" % (i, counter[i]) for i in sorted(counter))]
233+
items, inv = np.unique(d, return_inverse=True)
234+
freq = np.bincount(inv)
235+
row += ["@l" + " ".join("%g:%d" % (i, f) for i, f in zip(items, freq))]
238236
except Exception as e:
239237
verbose(2, "Failed to obtain stats/counts -- %s" % str(e))
240238
row += ['error']

nibabel/tests/test_scripts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ def test_nib_ls_multiple():
117117
assert_equal(
118118
[l[l.index('['):] for l in stdout_lines],
119119
[
120-
'[128, 96, 24, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [229725] [2, 1.2e+03]',
121-
'[ 32, 20, 12, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [15360] [46, 7.6e+02]',
122-
'[ 18, 28, 29] 9.00x8.00x7.00 [14616] [0.12, 93]',
120+
'[128, 96, 24, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [229725] [2, 1.2e+03]',
121+
'[ 32, 20, 12, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [15360] [46, 7.6e+02]',
122+
'[ 18, 28, 29] 9.00x8.00x7.00 [14616] [0.12, 93]',
123123
'[ 91, 109, 91] 2.00x2.00x2.00 error'
124124
]
125125
)

0 commit comments

Comments
 (0)