Skip to content

Commit fd26303

Browse files
committed
STY: Fix up some remaining old-style exceptions.
I think that is the end of it.
1 parent b2793ea commit fd26303

File tree

13 files changed

+43
-42
lines changed

13 files changed

+43
-42
lines changed

numpy/core/_mx_datetime_parser.py

Lines changed: 7 additions & 7 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -1,5 +1,5 @@
1
#-*- coding: latin-1 -*-
1
#-*- coding: latin-1 -*-
2-
"""
2+
"""
3
Date/Time string parsing module.
3
Date/Time string parsing module.
4
4
5
This code is a slightly modified version of Parser.py found in mx.DateTime
5
This code is a slightly modified version of Parser.py found in mx.DateTime
@@ -540,8 +540,8 @@ def _parse_date(text):
540
try:
540
try:
541
month = litmonthtable[litmonth]
541
month = litmonthtable[litmonth]
542
except KeyError:
542
except KeyError:
543-
raise ValueError,\
543+
raise ValueError(
544-
'wrong month name: "%s"' % litmonth
544+
'wrong month name: "%s"' % litmonth)
545
elif month:
545
elif month:
546
month = int(month)
546
month = int(month)
547
else:
547
else:
@@ -726,8 +726,8 @@ def datetime_from_string(text):
726
return dt.datetime(year,month,day,hour,minute,second, microsecond) - \
726
return dt.datetime(year,month,day,hour,minute,second, microsecond) - \
727
dt.timedelta(minutes=offset)
727
dt.timedelta(minutes=offset)
728
except ValueError, why:
728
except ValueError, why:
729-
raise RangeError,\
729+
raise RangeError(
730-
'Failed to parse "%s": %s' % (origtext, why)
730+
'Failed to parse "%s": %s' % (origtext, why))
731

731

732
def date_from_string(text):
732
def date_from_string(text):
733

733

@@ -745,8 +745,8 @@ def date_from_string(text):
745
try:
745
try:
746
return dt.datetime(year,month,day)
746
return dt.datetime(year,month,day)
747
except ValueError, why:
747
except ValueError, why:
748-
raise RangeError,\
748+
raise RangeError(
749-
'Failed to parse "%s": %s' % (text, why)
749+
'Failed to parse "%s": %s' % (text, why))
750

750

751
def validateDateTimeString(text):
751
def validateDateTimeString(text):
752

752

numpy/core/getlimits.py

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _init(self, dtype):
140
fmt = '%12.5e'
140
fmt = '%12.5e'
141
precname = 'half'
141
precname = 'half'
142
else:
142
else:
143-
raise ValueError, repr(dtype)
143+
raise ValueError(repr(dtype))
144

144

145
machar = MachAr(lambda v:array([v], dtype),
145
machar = MachAr(lambda v:array([v], dtype),
146
lambda v:_frz(v.astype(itype))[0],
146
lambda v:_frz(v.astype(itype))[0],

numpy/core/machar.py

Lines changed: 8 additions & 8 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
128
if any(temp1 - one != zero):
128
if any(temp1 - one != zero):
129
break
129
break
130
else:
130
else:
131-
raise RuntimeError, msg % (_, one.dtype)
131+
raise RuntimeError(msg % (_, one.dtype))
132
b = one
132
b = one
133
for _ in xrange(max_iterN):
133
for _ in xrange(max_iterN):
134
b = b + b
134
b = b + b
@@ -137,7 +137,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
137
if any(itemp != 0):
137
if any(itemp != 0):
138
break
138
break
139
else:
139
else:
140-
raise RuntimeError, msg % (_, one.dtype)
140+
raise RuntimeError(msg % (_, one.dtype))
141
ibeta = itemp
141
ibeta = itemp
142
beta = float_conv(ibeta)
142
beta = float_conv(ibeta)
143

143

@@ -152,7 +152,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
152
if any(temp1 - one != zero):
152
if any(temp1 - one != zero):
153
break
153
break
154
else:
154
else:
155-
raise RuntimeError, msg % (_, one.dtype)
155+
raise RuntimeError(msg % (_, one.dtype))
156

156

157
betah = beta / two
157
betah = beta / two
158
a = one
158
a = one
@@ -163,7 +163,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
163
if any(temp1 - one != zero):
163
if any(temp1 - one != zero):
164
break
164
break
165
else:
165
else:
166-
raise RuntimeError, msg % (_, one.dtype)
166+
raise RuntimeError(msg % (_, one.dtype))
167
temp = a + betah
167
temp = a + betah
168
irnd = 0
168
irnd = 0
169
if any(temp-a != zero):
169
if any(temp-a != zero):
@@ -191,7 +191,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
191
raise RuntimeError("could not determine machine tolerance "
191
raise RuntimeError("could not determine machine tolerance "
192
"for 'negep', locals() -> %s" % (locals()))
192
"for 'negep', locals() -> %s" % (locals()))
193
else:
193
else:
194-
raise RuntimeError, msg % (_, one.dtype)
194+
raise RuntimeError(msg % (_, one.dtype))
195
negep = -negep
195
negep = -negep
196
epsneg = a
196
epsneg = a
197

197

@@ -206,7 +206,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
206
a = a * beta
206
a = a * beta
207
machep = machep + 1
207
machep = machep + 1
208
else:
208
else:
209-
raise RuntimeError, msg % (_, one.dtype)
209+
raise RuntimeError(msg % (_, one.dtype))
210
eps = a
210
eps = a
211

211

212
# Determine ngrd
212
# Determine ngrd
@@ -234,7 +234,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
234
i = i + 1
234
i = i + 1
235
k = k + k
235
k = k + k
236
else:
236
else:
237-
raise RuntimeError, msg % (_, one.dtype)
237+
raise RuntimeError(msg % (_, one.dtype))
238
if ibeta != 10:
238
if ibeta != 10:
239
iexp = i + 1
239
iexp = i + 1
240
mx = k + k
240
mx = k + k
@@ -262,7 +262,7 @@ def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
262
else:
262
else:
263
break
263
break
264
else:
264
else:
265-
raise RuntimeError, msg % (_, one.dtype)
265+
raise RuntimeError(msg % (_, one.dtype))
266
minexp = -k
266
minexp = -k
267

267

268
# Determine maxexp, xmax
268
# Determine maxexp, xmax

numpy/core/numeric.py

Lines changed: 2 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -1109,9 +1109,9 @@ def rollaxis(a, axis, start=0):
1109
start += n
1109
start += n
1110
msg = 'rollaxis: %s (%d) must be >=0 and < %d'
1110
msg = 'rollaxis: %s (%d) must be >=0 and < %d'
1111
if not (0 <= axis < n):
1111
if not (0 <= axis < n):
1112-
raise ValueError, msg % ('axis', axis, n)
1112+
raise ValueError(msg % ('axis', axis, n))
1113
if not (0 <= start < n+1):
1113
if not (0 <= start < n+1):
1114-
raise ValueError, msg % ('start', start, n+1)
1114+
raise ValueError(msg % ('start', start, n+1))
1115
if (axis < start): # it's been removed
1115
if (axis < start): # it's been removed
1116
start -= 1
1116
start -= 1
1117
if axis==start:
1117
if axis==start:

numpy/distutils/mingw32ccompiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -355,7 +355,7 @@ def _build_import_library_x86():
355
log.warn('Failed to build import library for gcc. Linking will fail.')
355
log.warn('Failed to build import library for gcc. Linking will fail.')
356
#if not success:
356
#if not success:
357
# msg = "Couldn't find import library, and failed to build it."
357
# msg = "Couldn't find import library, and failed to build it."
358-
# raise DistutilsPlatformError, msg
358+
# raise DistutilsPlatformError(msg)
359
return
359
return
360

360

361
#=====================================
361
#=====================================

numpy/lib/_datasource.py

Lines changed: 2 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -633,7 +633,7 @@ def listdir(self):
633
633
634
"""
634
"""
635
if self._isurl(self._baseurl):
635
if self._isurl(self._baseurl):
636-
raise NotImplementedError, \
636+
raise NotImplementedError(
637-
"Directory listing of URLs, not supported yet."
637+
"Directory listing of URLs, not supported yet.")
638
else:
638
else:
639
return os.listdir(self._baseurl)
639
return os.listdir(self._baseurl)

numpy/lib/npyio.py

Lines changed: 3 additions & 3 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __getattribute__(self, key):
113
try:
113
try:
114
return object.__getattribute__(self, '_obj')[key]
114
return object.__getattribute__(self, '_obj')[key]
115
except KeyError:
115
except KeyError:
116-
raise AttributeError, key
116+
raise AttributeError(key)
117

117

118
def zipfile_factory(*args, **kwargs):
118
def zipfile_factory(*args, **kwargs):
119
import zipfile
119
import zipfile
@@ -353,8 +353,8 @@ def load(file, mmap_mode=None):
353
try:
353
try:
354
return _cload(fid)
354
return _cload(fid)
355
except:
355
except:
356-
raise IOError, \
356+
raise IOError(
357-
"Failed to interpret file %s as a pickle" % repr(file)
357+
"Failed to interpret file %s as a pickle" % repr(file))
358
finally:
358
finally:
359
if own_fid:
359
if own_fid:
360
fid.close()
360
fid.close()

numpy/lib/polynomial.py

Lines changed: 2 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -306,8 +306,8 @@ def polyint(p, m=1, k=None):
306
if len(k) == 1 and m > 1:
306
if len(k) == 1 and m > 1:
307
k = k[0]*NX.ones(m, float)
307
k = k[0]*NX.ones(m, float)
308
if len(k) < m:
308
if len(k) < m:
309-
raise ValueError, \
309+
raise ValueError(
310-
"k must be a scalar or a rank-1 array of length 1 or >m."
310+
"k must be a scalar or a rank-1 array of length 1 or >m.")
311

311

312
truepoly = isinstance(p, poly1d)
312
truepoly = isinstance(p, poly1d)
313
p = NX.asarray(p)
313
p = NX.asarray(p)

numpy/ma/core.py

Lines changed: 6 additions & 6 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ def masked_where(condition, a, copy=True):
1798

1798

1799
(cshape, ashape) = (cond.shape, a.shape)
1799
(cshape, ashape) = (cond.shape, a.shape)
1800
if cshape and cshape != ashape:
1800
if cshape and cshape != ashape:
1801-
raise IndexError("Inconsistant shape between the condition and the input"\
1801+
raise IndexError("Inconsistant shape between the condition and the input"
1802
" (got %s and %s)" % (cshape, ashape))
1802
" (got %s and %s)" % (cshape, ashape))
1803
if hasattr(a, '_mask'):
1803
if hasattr(a, '_mask'):
1804
cond = mask_or(cond, a._mask)
1804
cond = mask_or(cond, a._mask)
@@ -2703,7 +2703,7 @@ def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
2703
else:
2703
else:
2704
msg = "Mask and data not compatible: data size is %i, " + \
2704
msg = "Mask and data not compatible: data size is %i, " + \
2705
"mask size is %i."
2705
"mask size is %i."
2706-
raise MaskError, msg % (nd, nm)
2706+
raise MaskError(msg % (nd, nm))
2707
copy = True
2707
copy = True
2708
# Set the mask to the new value
2708
# Set the mask to the new value
2709
if _data._mask is nomask:
2709
if _data._mask is nomask:
@@ -2930,7 +2930,7 @@ def __getitem__(self, indx):
2930
# This test is useful, but we should keep things light...
2930
# This test is useful, but we should keep things light...
2931
# if getmask(indx) is not nomask:
2931
# if getmask(indx) is not nomask:
2932
# msg = "Masked arrays must be filled before they can be used as indices!"
2932
# msg = "Masked arrays must be filled before they can be used as indices!"
2933-
# raise IndexError, msg
2933+
# raise IndexError(msg)
2934
_data = ndarray.view(self, ndarray)
2934
_data = ndarray.view(self, ndarray)
2935
dout = ndarray.__getitem__(_data, indx)
2935
dout = ndarray.__getitem__(_data, indx)
2936
# We could directly use ndarray.__getitem__ on self...
2936
# We could directly use ndarray.__getitem__ on self...
@@ -2980,7 +2980,7 @@ def __setitem__(self, indx, value):
2980
# This test is useful, but we should keep things light...
2980
# This test is useful, but we should keep things light...
2981
# if getmask(indx) is not nomask:
2981
# if getmask(indx) is not nomask:
2982
# msg = "Masked arrays must be filled before they can be used as indices!"
2982
# msg = "Masked arrays must be filled before they can be used as indices!"
2983-
# raise IndexError, msg
2983+
# raise IndexError(msg)
2984
_data = ndarray.view(self, ndarray.__getattribute__(self, '_baseclass'))
2984
_data = ndarray.view(self, ndarray.__getattribute__(self, '_baseclass'))
2985
_mask = ndarray.__getattribute__(self, '_mask')
2985
_mask = ndarray.__getattribute__(self, '_mask')
2986
if isinstance(indx, basestring):
2986
if isinstance(indx, basestring):
@@ -3779,7 +3779,7 @@ def __ipow__(self, other):
3779
def __float__(self):
3779
def __float__(self):
3780
"Convert to float."
3780
"Convert to float."
3781
if self.size > 1:
3781
if self.size > 1:
3782-
raise TypeError("Only length-1 arrays can be converted "\
3782+
raise TypeError("Only length-1 arrays can be converted "
3783
"to Python scalars")
3783
"to Python scalars")
3784
elif self._mask:
3784
elif self._mask:
3785
warnings.warn("Warning: converting a masked element to nan.")
3785
warnings.warn("Warning: converting a masked element to nan.")
@@ -3789,7 +3789,7 @@ def __float__(self):
3789
def __int__(self):
3789
def __int__(self):
3790
"Convert to int."
3790
"Convert to int."
3791
if self.size > 1:
3791
if self.size > 1:
3792-
raise TypeError("Only length-1 arrays can be converted "\
3792+
raise TypeError("Only length-1 arrays can be converted "
3793
"to Python scalars")
3793
"to Python scalars")
3794
elif self._mask:
3794
elif self._mask:
3795
raise MaskError('Cannot convert masked element to a Python int.')
3795
raise MaskError('Cannot convert masked element to a Python int.')

numpy/oldnumeric/ma.py

Lines changed: 2 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -614,10 +614,10 @@ def __array__ (self, t=None, context=None):
614
"numeric because data\n is masked in one or "\
614
"numeric because data\n is masked in one or "\
615
"more locations.");
615
"more locations.");
616
return self._data
616
return self._data
617-
#raise MAError, \
617+
#raise MAError(
618
# """Cannot automatically convert masked array to numeric because data
618
# """Cannot automatically convert masked array to numeric because data
619
# is masked in one or more locations.
619
# is masked in one or more locations.
620-
# """
620+
# """)
621
else:
621
else:
622
func, args, i = context
622
func, args, i = context
623
fills = ufunc_fills.get(func)
623
fills = ufunc_fills.get(func)

numpy/oldnumeric/precision.py

Lines changed: 2 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -33,7 +33,8 @@ def _lookup(table, key, required_bits):
33
for bits, typecode in lst:
33
for bits, typecode in lst:
34
if bits >= required_bits:
34
if bits >= required_bits:
35
return typecode
35
return typecode
36-
raise PrecisionError, key+" of "+str(required_bits)+" bits not available on this system"
36+
raise PrecisionError(key + " of " + str(required_bits) +
37+
" bits not available on this system")
37

38

38
Character = 'c'
39
Character = 'c'
39

40

numpy/oldnumeric/random_array.py

Lines changed: 4 additions & 4 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -19,10 +19,10 @@ def seed(x=0, y=0):
19
mt.seed((x,y))
19
mt.seed((x,y))
20

20

21
def get_seed():
21
def get_seed():
22-
raise NotImplementedError, \
22+
raise NotImplementedError(
23-
"If you want to save the state of the random number generator.\n"\
23+
"If you want to save the state of the random number generator.\n"
24-
"Then you should use obj = numpy.random.get_state() followed by.\n"\
24+
"Then you should use obj = numpy.random.get_state() followed by.\n"
25-
"numpy.random.set_state(obj)."
25+
"numpy.random.set_state(obj).")
26

26

27
def random(shape=[]):
27
def random(shape=[]):
28
"random(n) or random([n, m, ...]) returns array of random numbers"
28
"random(n) or random([n, m, ...]) returns array of random numbers"

numpy/testing/nulltester.py

Lines changed: 3 additions & 3 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -9,7 +9,7 @@
9

9

10
class NullTester(object):
10
class NullTester(object):
11
def test(self, labels=None, *args, **kwargs):
11
def test(self, labels=None, *args, **kwargs):
12-
raise ImportError, \
12+
raise ImportError(
13-
'Need nose >=0.10 for tests - see %s' % \
13+
'Need nose >=0.10 for tests - see %s' %
14-
'http://somethingaboutorange.com/mrl/projects/nose'
14+
'http://somethingaboutorange.com/mrl/projects/nose')
15
bench = test
15
bench = test

0 commit comments

Comments
 (0)