8000 2to3: Apply `raise` fixes. Closes #3077. · numpy/numpy@3655b73 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3655b73

Browse files
committed
2to3: Apply raise fixes. Closes #3077.
Replaces the raise Exception, msg: form with raise Exception(msg):
1 parent d1e692d commit 3655b73

File tree

12 files changed

+27
-27
lines changed

12 files changed

+27
-27
lines changed

doc/numpybook/comparison/weave/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
def filter(a):
44
if a.ndim != 2:
5-
raise ValueError, "a must be 2-d"
5+
raise ValueError("a must be 2-d")
66
code = r"""
77
int i,j;
88
for(i=1;i<Na[0]-1;i++) {

doc/numpybook/comparison/weave/inline.py

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

44
def example1(a):
55
if not isinstance(a, list):
6-
raise ValueError, "argument must be a list"
6+
raise ValueError("argument must be a list")
77
code = r"""
88
int i;
99
py::tuple results(2);
@@ -18,7 +18,7 @@ def example1(a):
1818

1919
def arr(a):
2020
if a.ndim != 2:
21-
raise ValueError, "a must be 2-d"
21+
raise ValueError("a must be 2-d")
2222
code = r"""
2323
int i,j;
2424
for(i=1;i<Na[0]-1;i++) {

numpy/core/code_generators/generate_numpy_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ def do_generate_api(targets, sources):
221221
multiarray_api_dict[name] = TypeApi(name, index, 'PyTypeObject', api_name)
222222

223223
if len(multiarray_api_dict) != len(multiarray_api_index):
224-
raise AssertionError, "Multiarray API size mismatch %d %d" % \
225-
(len(multiarray_api_dict), len(multiarray_api_index))
224+
raise AssertionError("Multiarray API size mismatch %d %d" %
225+
(len(multiarray_api_dict), len(multiarray_api_index)))
226226

227227
extension_list = []
228228
for name, index in genapi.order_dict(multiarray_api_index):

numpy/core/records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def __setattr__(self, attr, val):
436436
fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
437437
if attr not in fielddict:
438438
exctype, value = sys.exc_info()[:2]
439-
raise exctype, value
439+
341A raise exctype(value)
440440
else:
441441
fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
442442
if attr not in fielddict:

numpy/f2py/auxfuncs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def __init__(self,mess):
447447
self.mess = mess
448448
def __call__(self,var):
449449
mess = '\n\n var = %s\n Message: %s\n' % (var,self.mess)
450-
raise F2PYError,mess
450+
raise F2PYError(mess)
451451

452452
def l_and(*f):
453453
l,l2='lambda v',[]

numpy/lib/polynomial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
564564
if w is not None:
565565
w = NX.asarray(w) + 0.0
566566
if w.ndim != 1:
567-
raise TypeError, "expected a 1-d array for weights"
567+
raise TypeError("expected a 1-d array for weights")
568568
if w.shape[0] != y.shape[0] :
569-
raise TypeError, "expected w and y to have the same length"
569+
raise TypeError("expected w and y to have the same length")
570570
lhs *= w[:, NX.newaxis]
571571
if rhs.ndim == 2:
572572
rhs *= w[:, NX.newaxis]

numpy/ma/extras.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,9 +1865,9 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
18651865
if w is not None:
18661866
w = asarray(w)
18671867
if w.ndim != 1:
1868-
raise TypeError, "expected a 1-d array for weights"
1868+
raise TypeError("expected a 1-d array for weights")
18691869
if w.shape[0] != y.shape[0] :
1870-
raise TypeError, "expected w and y to have the same length"
1870+
raise TypeError("expected w and y to have the same length")
18711871
m = mask_or(m, getmask(w))
18721872

18731873
if m is not nomask:

numpy/ma/mrecords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def __setattr__(self, attr, val):
252252
optinfo = ndarray.__getattribute__(self, '_optinfo') or {}
253253
if not (attr in fielddict or attr in optinfo):
254254
exctype, value = sys.exc_info()[:2]
255-
raise exctype, value
255+
raise exctype(value)
256256
else:
257257
# Get the list of names ......
258258
fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}

numpy/oldnumeric/arrayfns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def array_set(vals1, indices, vals2):
2020
vals1 = asarray(vals1)
2121
vals2 = asarray(vals2)
2222
if vals1.ndim != vals2.ndim or vals1.ndim < 1:
23-
raise error, "vals1 and vals2 must have same number of dimensions (>=1)"
23+
raise error("vals1 and vals2 must have same number of dimensions (>=1)")
2424
vals1[indices] = vals2
2525

2626
from numpy import digitize
@@ -38,7 +38,7 @@ def interp(y, x, z, typ=None):
3838
if typ == 'f':
3939
return res.astype('f')
4040

41-
raise error, "incompatible typecode"
41+
raise error("incompatible typecode")
4242

4343
def nz(x):
4444
x = asarray(x,dtype=np.ubyte)

numpy/oldnumeric/random_array.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,20 @@ def test():
201201
mt.set_state(obj)
202202
obj2 = mt.get_state()
203203
if (obj2[1] - obj[1]).any():
204-
raise SystemExit, "Failed seed test."
204+
raise SystemExit("Failed seed test.")
205205
print "First random number is", random()
206206
print "Average of 10000 random numbers is", np.sum(random(10000),axis=0)/10000.
207207
x = random([10,1000])
208208
if len(x.shape) != 2 or x.shape[0] != 10 or x.shape[1] != 1000:
209-
raise SystemExit, "random returned wrong shape"
209+
raise SystemExit("random returned wrong shape")
210210
x.shape = (10000,)
211211
print "Average of 100 by 100 random numbers is", np.sum(x,axis=0)/10000.
212212
y = uniform(0.5,0.6, (1000,10))
213213
if len(y.shape) !=2 or y.shape[0] != 1000 or y.shape[1] != 10:
214-
raise SystemExit, "uniform returned wrong shape"
214+
raise SystemExit("uniform returned wrong shape")
215215
y.shape = (10000,)
216216
if np.minimum.reduce(y) <= 0.5 or np.maximum.reduce(y) >= 0.6:
217-
raise SystemExit, "uniform returned out of desired range"
217+
raise SystemExit("uniform returned out of desired range")
218218
print "randint(1, 10, shape=[50])"
219219
print randint(1, 10, shape=[50])
220220
print "permutation(10)", permutation(10)
@@ -224,18 +224,18 @@ def test():
224224
s = 3.0
225225
x = normal(2.0, s, [10, 1000])
226226
if len(x.shape) != 2 or x.shape[0] != 10 or x.shape[1] != 1000:
227-
raise SystemExit, "standard_normal returned wrong shape"
227+
raise SystemExit("standard_normal returned wrong shape")
228228
x.shape = (10000,)
229229
mean_var_test(x, "normally distributed numbers with mean 2 and variance %f"%(s**2,), 2, s**2, 0)
230230
x = exponential(3, 10000)
231231
mean_var_test(x, "random numbers exponentially distributed with mean %f"%(s,), s, s**2, 2)
232232
x = multivariate_normal(np.array([10,20]), np.array(([1,2],[2,4])))
233233
print "\nA multivariate normal", x
234-
if x.shape != (2,): raise SystemExit, "multivariate_normal returned wrong shape"
234+
if x.shape != (2,): raise SystemExit("multivariate_normal returned wrong shape")
235235
x = multivariate_normal(np.array([10,20]), np.array([[1,2],[2,4]]), [4,3])
236236
print "A 4x3x2 array containing multivariate normals"
237237
print x
238-
if x.shape != (4,3,2): raise SystemExit, "multivariate_normal returned wrong shape"
238+
if x.shape != (4,3,2): raise SystemExit("multivariate_normal returned wrong shape")
239239
x = multivariate_normal(np.array([-100,0,100]), np.array([[3,2,1],[2,2,1],[1,1,1]]), 10000)
240240
x_mean = np.sum(x,axis=0)/10000.
241241
print "Average of 10000 multivariate normals with mean [-100,0,100]"

0 commit comments

Comments
 (0)
0