summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-02-28 17:23:13 -0700
committerCharles Harris <charlesr.harris@gmail.com>2013-03-01 08:35:12 -0700
commit3655b732bd08022dab8498b44191d6c4049bc7a8 (patch)
treea2a2210d560d5696e47a5dcf5d969faa8d21ad79 /numpy
parentd1e692d70da7532b02d752d0842987333bd76c70 (diff)
downloadnumpy-3655b732bd08022dab8498b44191d6c4049bc7a8.tar.gz
2to3: Apply `raise` fixes. Closes #3077.
Replaces the raise Exception, msg: form with raise Exception(msg):
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/generate_numpy_api.py4
-rw-r--r--numpy/core/records.py2
-rw-r--r--numpy/f2py/auxfuncs.py2
-rw-r--r--numpy/lib/polynomial.py4
-rw-r--r--numpy/ma/extras.py4
-rw-r--r--numpy/ma/mrecords.py2
-rw-r--r--numpy/oldnumeric/arrayfns.py4
-rw-r--r--numpy/oldnumeric/random_array.py14
-rw-r--r--numpy/oldnumeric/rng.py10
9 files changed, 23 insertions, 23 deletions
diff --git a/numpy/core/code_generators/generate_numpy_api.py b/numpy/core/code_generators/generate_numpy_api.py
index 7cd4b9f6a..463fe1695 100644
--- a/numpy/core/code_generators/generate_numpy_api.py
+++ b/numpy/core/code_generators/generate_numpy_api.py
@@ -221,8 +221,8 @@ def do_generate_api(targets, sources):
multiarray_api_dict[name] = TypeApi(name, index, 'PyTypeObject', api_name)
if len(multiarray_api_dict) != len(multiarray_api_index):
- raise AssertionError, "Multiarray API size mismatch %d %d" % \
- (len(multiarray_api_dict), len(multiarray_api_index))
+ raise AssertionError("Multiarray API size mismatch %d %d" %
+ (len(multiarray_api_dict), len(multiarray_api_index)))
extension_list = []
for name, index in genapi.order_dict(multiarray_api_index):
diff --git a/numpy/core/records.py b/numpy/core/records.py
index 964b4a54e..2e55c48fb 100644
--- a/numpy/core/records.py
+++ b/numpy/core/records.py
@@ -436,7 +436,7 @@ class recarray(ndarray):
fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
if attr not in fielddict:
exctype, value = sys.exc_info()[:2]
- raise exctype, value
+ raise exctype(value)
else:
fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
if attr not in fielddict:
diff --git a/numpy/f2py/auxfuncs.py b/numpy/f2py/auxfuncs.py
index a12d92b7e..72af373db 100644
--- a/numpy/f2py/auxfuncs.py
+++ b/numpy/f2py/auxfuncs.py
@@ -447,7 +447,7 @@ class throw_error:
self.mess = mess
def __call__(self,var):
mess = '\n\n var = %s\n Message: %s\n' % (var,self.mess)
- raise F2PYError,mess
+ raise F2PYError(mess)
def l_and(*f):
l,l2='lambda v',[]
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index fad06f4df..421efb675 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -564,9 +564,9 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
if w is not None:
w = NX.asarray(w) + 0.0
if w.ndim != 1:
- raise TypeError, "expected a 1-d array for weights"
+ raise TypeError("expected a 1-d array for weights")
if w.shape[0] != y.shape[0] :
- raise TypeError, "expected w and y to have the same length"
+ raise TypeError("expected w and y to have the same length")
lhs *= w[:, NX.newaxis]
if rhs.ndim == 2:
rhs *= w[:, NX.newaxis]
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index c5b3a3957..3133b168b 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -1865,9 +1865,9 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
if w is not None:
w = asarray(w)
if w.ndim != 1:
- raise TypeError, "expected a 1-d array for weights"
+ raise TypeError("expected a 1-d array for weights")
if w.shape[0] != y.shape[0] :
- raise TypeError, "expected w and y to have the same length"
+ raise TypeError("expected w and y to have the same length")
m = mask_or(m, getmask(w))
if m is not nomask:
diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py
index 44d273d34..d3b2de3ba 100644
--- a/numpy/ma/mrecords.py
+++ b/numpy/ma/mrecords.py
@@ -252,7 +252,7 @@ class MaskedRecords(MaskedArray, object):
optinfo = ndarray.__getattribute__(self, '_optinfo') or {}
if not (attr in fielddict or attr in optinfo):
exctype, value = sys.exc_info()[:2]
- raise exctype, value
+ raise exctype(value)
else:
# Get the list of names ......
fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
diff --git a/numpy/oldnumeric/arrayfns.py b/numpy/oldnumeric/arrayfns.py
index 683ed309d..54992de57 100644
--- a/numpy/oldnumeric/arrayfns.py
+++ b/numpy/oldnumeric/arrayfns.py
@@ -20,7 +20,7 @@ def array_set(vals1, indices, vals2):
vals1 = asarray(vals1)
vals2 = asarray(vals2)
if vals1.ndim != vals2.ndim or vals1.ndim < 1:
- raise error, "vals1 and vals2 must have same number of dimensions (>=1)"
+ raise error("vals1 and vals2 must have same number of dimensions (>=1)")
vals1[indices] = vals2
from numpy import digitize
@@ -38,7 +38,7 @@ def interp(y, x, z, typ=None):
if typ == 'f':
return res.astype('f')
- raise error, "incompatible typecode"
+ raise error("incompatible typecode")
def nz(x):
x = asarray(x,dtype=np.ubyte)
diff --git a/numpy/oldnumeric/random_array.py b/numpy/oldnumeric/random_array.py
index 777e2a645..7141e564b 100644
--- a/numpy/oldnumeric/random_array.py
+++ b/numpy/oldnumeric/random_array.py
@@ -201,20 +201,20 @@ def test():
mt.set_state(obj)
obj2 = mt.get_state()
if (obj2[1] - obj[1]).any():
- raise SystemExit, "Failed seed test."
+ raise SystemExit("Failed seed test.")
print "First random number is", random()
print "Average of 10000 random numbers is", np.sum(random(10000),axis=0)/10000.
x = random([10,1000])
if len(x.shape) != 2 or x.shape[0] != 10 or x.shape[1] != 1000:
- raise SystemExit, "random returned wrong shape"
+ raise SystemExit("random returned wrong shape")
x.shape = (10000,)
print "Average of 100 by 100 random numbers is", np.sum(x,axis=0)/10000.
y = uniform(0.5,0.6, (1000,10))
if len(y.shape) !=2 or y.shape[0] != 1000 or y.shape[1] != 10:
- raise SystemExit, "uniform returned wrong shape"
+ raise SystemExit("uniform returned wrong shape")
y.shape = (10000,)
if np.minimum.reduce(y) <= 0.5 or np.maximum.reduce(y) >= 0.6:
- raise SystemExit, "uniform returned out of desired range"
+ raise SystemExit("uniform returned out of desired range")
print "randint(1, 10, shape=[50])"
print randint(1, 10, shape=[50])
print "permutation(10)", permutation(10)
@@ -224,18 +224,18 @@ def test():
s = 3.0
x = normal(2.0, s, [10, 1000])
if len(x.shape) != 2 or x.shape[0] != 10 or x.shape[1] != 1000:
- raise SystemExit, "standard_normal returned wrong shape"
+ raise SystemExit("standard_normal returned wrong shape")
x.shape = (10000,)
mean_var_test(x, "normally distributed numbers with mean 2 and variance %f"%(s**2,), 2, s**2, 0)
x = exponential(3, 10000)
mean_var_test(x, "random numbers exponentially distributed with mean %f"%(s,), s, s**2, 2)
x = multivariate_normal(np.array([10,20]), np.array(([1,2],[2,4])))
print "\nA multivariate normal", x
- if x.shape != (2,): raise SystemExit, "multivariate_normal returned wrong shape"
+ if x.shape != (2,): raise SystemExit("multivariate_normal returned wrong shape")
x = multivariate_normal(np.array([10,20]), np.array([[1,2],[2,4]]), [4,3])
print "A 4x3x2 array containing multivariate normals"
print x
- if x.shape != (4,3,2): raise SystemExit, "multivariate_normal returned wrong shape"
+ if x.shape != (4,3,2): raise SystemExit("multivariate_normal returned wrong shape")
x = multivariate_normal(np.array([-100,0,100]), np.array([[3,2,1],[2,2,1],[1,1,1]]), 10000)
x_mean = np.sum(x,axis=0)/10000.
print "Average of 10000 multivariate normals with mean [-100,0,100]"
diff --git a/numpy/oldnumeric/rng.py b/numpy/oldnumeric/rng.py
index 28d3f16df..38b182eae 100644
--- a/numpy/oldnumeric/rng.py
+++ b/numpy/oldnumeric/rng.py
@@ -36,7 +36,7 @@ class Distribution(object):
class ExponentialDistribution(Distribution):
def __init__(self, lambda_):
if (lambda_ <= 0):
- raise error, "parameter must be positive"
+ raise error("parameter must be positive")
Distribution.__init__(self, 'exponential', lambda_)
def density(x):
@@ -51,7 +51,7 @@ class LogNormalDistribution(Distribution):
m = float(m)
s = float(s)
if (s <= 0):
- raise error, "standard deviation must be positive"
+ raise error("standard deviation must be positive")
Distribution.__init__(self, 'lognormal', m, s)
sn = math.log(1.0+s*s/(m*m));
self._mn = math.log(m)-0.5*sn
@@ -69,7 +69,7 @@ class NormalDistribution(Distribution):
m = float(m)
s = float(s)
if (s <= 0):
- raise error, "standard deviation must be positive"
+ raise error("standard deviation must be positive")
Distribution.__init__(self, 'normal', m, s)
self._fac = 1.0/math.sqrt(2*math.pi)/s
@@ -84,7 +84,7 @@ class UniformDistribution(Distribution):
b = float(b)
width = b-a
if (width <=0):
- raise error, "width of uniform distribution must be > 0"
+ raise error("width of uniform distribution must be > 0")
Distribution.__init__(self, 'uniform', a, b)
self._fac = 1.0/width
@@ -106,7 +106,7 @@ class CreateGenerator(object):
if dist is None:
dist = default_distribution
if not isinstance(dist, Distribution):
- raise error, "Not a distribution object"
+ raise error("Not a distribution object")
self._dist = dist
def ranf(self):