Skip to content

Commit b7c2c47

Browse files
committed
Drop some leftover py2 compat
1 parent fd75bb8 commit b7c2c47

File tree

6 files changed

+16
-29
lines changed

6 files changed

+16
-29
lines changed

src/IsoSpecPy/IsoSpecPy.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
from collections import namedtuple, OrderedDict
2424
import math
2525

26-
try:
27-
xrange
28-
except NameError:
29-
xrange = range
30-
3126
regex_pattern = re.compile('([A-Z][a-z]?)(-?[0-9]*)')
3227
ParsedFormula = namedtuple('ParsedFormula', 'atomCounts masses probs elems')
3328

@@ -200,9 +195,9 @@ def __init__(self, formula="",
200195

201196
if get_confs:
202197
i = 0
203-
for j in xrange(self.dimNumber):
198+
for j in range(self.dimNumber):
204199
newl = []
205-
for k in xrange(self.isotopeNumbers[j]):
200+
for k in range(self.isotopeNumbers[j]):
206201
newl.append(i)
207202
i += 1
208203
offsets.append(tuple(newl))
@@ -289,10 +284,10 @@ def np_probs(self):
289284

290285
def __iter__(self):
291286
if hasattr(self, "confs") and self.confs is not None:
292-
for i in xrange(self.size):
287+
for i in range(self.size):
293288
yield(self.masses[i], self.probs[i], self.confs[i])
294289
else:
295-
for i in xrange(self.size):
290+
for i in range(self.size):
296291
yield (self.masses[i], self.probs[i])
297292

298293
def __getitem__(self, idx):

src/IsoSpecPy/IsoSpecPyOld.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# IsoSpec is distributed in the hope that it will be useful,
1111
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1313
#
1414
# You should have received a copy of the Simplified BSD Licence
1515
# along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
@@ -26,10 +26,6 @@
2626
The current API is implemented in __init__.py, use that instead
2727
'''
2828

29-
try:
30-
xrange
31-
except NameError:
32-
xrange = range
3329

3430
import re
3531
from .IsoSpecPy import IsoTotalProb, IsoThreshold
@@ -80,7 +76,7 @@ def __init__(
8076
except KeyError:
8177
raise Exception("Invalid ISO method")
8278

83-
# Reference to iso needs to be held in this object: it will deallocate masses/lprobs/etc arrays on C++ side if we
79+
# Reference to iso needs to be held in this object: it will deallocate masses/lprobs/etc arrays on C++ side if we
8480
# allow GC to collect it prematurely
8581
self.iso = algo(_stopCondition)
8682

@@ -136,7 +132,7 @@ def getConfs(self):
136132
masses = list(masses)
137133
logProbs= list(logProbs)
138134
confs = []
139-
for i in xrange(rows_no):
135+
for i in range(rows_no):
140136
confs.append([x for sublist in isoCounts[i] for x in sublist])
141137
return masses, logProbs, confs
142138

@@ -157,7 +153,7 @@ def getConfsNumpy(self):
157153
def splitConf(self, l, offset = 0):
158154
conf = []
159155
idx = self.allIsotopeNumber * offset
160-
for i in xrange(self.dimNumber):
156+
for i in range(self.dimNumber):
161157
conf.append(tuple(l[idx:idx+self._isotopeNumbers[i]]))
162158
idx += self._isotopeNumbers[i]
163159
return tuple(conf)
@@ -169,7 +165,7 @@ def printConfs(self):
169165
masses, logProbs, isoCounts = self.getConfsRaw()
170166
confs = []
171167
step = sum(self._isotopeNumbers)
172-
for i in xrange(len(masses)):
168+
for i in range(len(masses)):
173169
confs.append((masses[i], logProbs[i], self.splitConf(isoCounts, i)))
174170

175171
for conf in confs:
@@ -184,7 +180,7 @@ def __init__(self, iso, bin_w):
184180
self.bin_w = bin_w
185181
masses, logProbs, _isoCounts = iso.getConfsRaw()
186182
dd = defaultdict(Summator)
187-
for i in xrange(len(masses)):
183+
for i in range(len(masses)):
188184
dd[float(int(masses[i]/bin_w))*bin_w].add(math.exp(logProbs[i]))
189185
for key, val in dd.items():
190186
self[key] = val.get()

src/IsoSpecPy/PeriodicTbl.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
from .isoFFI import isoFFI
22
from collections import defaultdict
33

4-
try:
5-
xrange
6-
except NameError:
7-
xrange = range
84

95
number_of_isotopic_entries = isoFFI.clib.NUMBER_OF_ISOTOPIC_ENTRIES
106

@@ -13,7 +9,7 @@
139
symbol_to_probs = defaultdict(tuple)
1410
symbol_to_atomic_number = {}
1511

16-
for i in xrange(number_of_isotopic_entries):
12+
for i in range(number_of_isotopic_entries):
1713
symbol = isoFFI.ffi.string(isoFFI.clib.elem_table_symbol[i]).decode("ascii")
1814
symbol_to_masses[symbol] += (isoFFI.clib.elem_table_mass[i],)
1915
symbol_to_massNo[symbol] += (isoFFI.clib.elem_table_massNo[i],)

tests/cppyy/cpt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
i = cppyy.gbl.IsoSpec.Iso("C100H100")
66
iso = cppyy.gbl.IsoSpec.IsoThresholdGenerator(cppyy.gbl.std.move(i), 0.01)
77
while iso.advanceToNextConfiguration():
8-
print iso.prob(), iso.mass()
8+
print(iso.prob(), iso.mass())

tests/cppyy/overhead-cppyy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
t = 0.0
13-
for x in tqdm(xrange(1000000)):
13+
for x in tqdm(range(1000000)):
1414
i = cppyy.gbl.IsoSpec.Iso("C100H100N100O100")
1515
t += i.getTheoreticalAverageMass()
16-
print t
16+
print(t)

tests/cppyy/overhead.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from tqdm import tqdm
33

44
t = 0.0
5-
for x in tqdm(xrange(100000)):
5+
for x in tqdm(range(100000)):
66
i = IsoSpecPy.Iso("C100H100N100O100")
77
t += i.getTheoreticalAverageMass()
8-
print t
8+
print(t)

0 commit comments

Comments
 (0)