[Scipy-svn] r6934 - in trunk/scipy/stats: . tests

scipy-svn@scip... scipy-svn@scip...
Sat Nov 20 12:19:29 CST 2010


Author: warren.weckesser
Date: 2010-11-20 12:19:28 -0600 (Sat, 20 Nov 2010)
New Revision: 6934

Modified:
   trunk/scipy/stats/distributions.py
   trunk/scipy/stats/morestats.py
   trunk/scipy/stats/mstats_basic.py
   trunk/scipy/stats/stats.py
   trunk/scipy/stats/tests/test_fit.py
Log:
ENH: stats: update 'raise' statements

Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py	2010-11-20 18:13:28 UTC (rev 6933)
+++ trunk/scipy/stats/distributions.py	2010-11-20 18:19:28 UTC (rev 6934)
@@ -566,7 +566,7 @@
         args, loc, scale = self._fix_loc_scale(args, loc, scale)
         cond = logical_and(self._argcheck(*args),(scale >= 0))
         if not all(cond):
-            raise ValueError, "Domain error in arguments."
+            raise ValueError("Domain error in arguments.")
 
         # self._size is total size of all output values
         self._size = product(size, axis=0)
@@ -713,7 +713,7 @@
         """
         alpha = arr(alpha)
         if any((alpha > 1) | (alpha < 0)):
-            raise ValueError, "alpha must be between 0 and 1 inclusive"
+            raise ValueError("alpha must be between 0 and 1 inclusive")
         q1 = (1.0-alpha)/2
         q2 = (1.0+alpha)/2
         a = self.ppf(q1, *args, **kwds)
@@ -1536,8 +1536,8 @@
 
         """
         if (floor(n) != n):
-            raise ValueError, "Moment must be an integer."
-        if (n < 0): raise ValueError, "Moment must be positive."
+            raise ValueError("Moment must be an integer.")
+        if (n < 0): raise ValueError("Moment must be positive.")
         if (n == 0): return 1.0
         if (n > 0) and (n < 5):
             signature = inspect.getargspec(self._stats.im_func)
@@ -1581,7 +1581,7 @@
             scale = theta[-1]
             args = tuple(theta[:-2])
         except IndexError:
-            raise ValueError, "Not enough input arguments."
+            raise ValueError("Not enough input arguments.")
         if not self._argcheck(*args) or scale <= 0:
             return inf
         x = arr((x-loc) / scale)
@@ -1616,7 +1616,7 @@
             restore = None
         else:
             if len(fixedn) == len(index):
-                raise ValueError, "All parameters fixed. There is nothing to optimize."
+                raise ValueError("All parameters fixed. There is nothing to optimize.")
             def restore(args, theta):
                 # Replace with theta for all numbers not in fixedn
                 # This allows the non-fixed values to vary, but
@@ -1683,7 +1683,7 @@
         """
         Narg = len(args)
         if Narg > self.numargs:
-                raise ValueError, "Too many input arguments."
+                raise ValueError("Too many input arguments.")
         start = [None]*2
         if (Narg < self.numargs) or not (kwds.has_key('loc') and
                                          kwds.has_key('scale')):
@@ -1704,7 +1704,7 @@
             try:
                 optimizer = getattr(optimize, optimizer)
             except AttributeError:
-                raise ValueError, "%s is not a valid optimizer" % optimizer
+                raise ValueError("%s is not a valid optimizer" % optimizer)
         vals = optimizer(func,x0,args=(ravel(data),),disp=0)
         vals = tuple(vals)
         if restore is not None:
@@ -4504,7 +4504,7 @@
     else:
         qk = arr(qk)
         if len(qk) != len(pk):
-            raise ValueError, "qk and pk must have same length."
+            raise ValueError("qk and pk must have same length.")
         qk = 1.0*qk / sum(qk,axis=0)
         # If qk is zero anywhere, then unless pk is zero at those places
         #   too, the relative entropy is infinite.
@@ -5400,8 +5400,8 @@
 
         """
         if (floor(n) != n):
-            raise ValueError, "Moment must be an integer."
-        if (n < 0): raise ValueError, "Moment must be positive."
+            raise ValueError("Moment must be an integer.")
+        if (n < 0): raise ValueError("Moment must be positive.")
         if (n == 0): return 1.0
         if (n > 0) and (n < 5):
             signature = inspect.getargspec(self._stats.im_func)

Modified: trunk/scipy/stats/morestats.py
===================================================================
--- trunk/scipy/stats/morestats.py	2010-11-20 18:13:28 UTC (rev 6933)
+++ trunk/scipy/stats/morestats.py	2010-11-20 18:19:28 UTC (rev 6934)
@@ -298,11 +298,11 @@
     res = inspect.getargspec(ppf_func)
     if not ('loc' == res[0][-2] and 'scale' == res[0][-1] and \
             0.0==res[-1][-2] and 1.0==res[-1][-1]):
-        raise ValueError, "Function has does not have default location", \
-              "and scale parameters\n  that are 0.0 and 1.0 respectively."
+        raise ValueError("Function has does not have default location "
+              "and scale parameters\n  that are 0.0 and 1.0 respectively.")
     if (len(sparams) < len(res[0])-len(res[-1])-1) or \
        (len(sparams) > len(res[0])-3):
-        raise ValueError, "Incorrect number of shape parameters."
+        raise ValueError("Incorrect number of shape parameters.")
     """
     osm = ppf_func(Ui,*sparams)
     osr = sort(x)
@@ -340,11 +340,11 @@
     res = inspect.getargspec(ppf_func)
     if not ('loc' == res[0][-2] and 'scale' == res[0][-1] and \
             0.0==res[-1][-2] and 1.0==res[-1][-1]):
-        raise ValueError, "Function has does not have default location", \
-              "and scale parameters\n  that are 0.0 and 1.0 respectively."
+        raise ValueError("Function has does not have default location "
+              "and scale parameters\n  that are 0.0 and 1.0 respectively.")
     if (1 < len(res[0])-len(res[-1])-1) or \
        (1 > len(res[0])-3):
-        raise ValueError, "Must be a one-parameter family."
+        raise ValueError("Must be a one-parameter family.")
     """
     N = len(x)
     # compute uniform median statistics

Modified: trunk/scipy/stats/mstats_basic.py
===================================================================
--- trunk/scipy/stats/mstats_basic.py	2010-11-20 18:13:28 UTC (rev 6933)
+++ trunk/scipy/stats/mstats_basic.py	2010-11-20 18:19:28 UTC (rev 6934)
@@ -686,7 +686,7 @@
     else:
         x = ma.asarray(x).flatten()
         if len(x) != n:
-            raise ValueError, "Incompatible lengths ! (%s<>%s)" % (n,len(x))
+            raise ValueError("Incompatible lengths ! (%s<>%s)" % (n,len(x)))
     m = ma.mask_or(ma.getmask(x), ma.getmask(y))
     y._mask = x._mask = m
     ny = y.count()
@@ -760,7 +760,7 @@
 def ttest_rel(a,b,axis=None):
     a, b, axis = _chk2_asarray(a, b, axis)
     if len(a)!=len(b):
-        raise ValueError, 'unequal length arrays'
+        raise ValueError('unequal length arrays')
     (x1, x2) = (a.mean(axis), b.mean(axis))
     (v1, v2) = (a.var(axis=axis, ddof=1), b.var(axis=axis, ddof=1))
     n = a.count(axis)
@@ -840,7 +840,7 @@
     ties = count_tied_groups(ranks)
     T = 1. - np.sum(v*(k**3-k) for (k,v) in ties.iteritems())/float(ntot**3-ntot)
     if T == 0:
-        raise ValueError, 'All numbers are identical in kruskal'
+        raise ValueError('All numbers are identical in kruskal')
     H /= T
     #
     df = len(output) - 1

Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2010-11-20 18:13:28 UTC (rev 6933)
+++ trunk/scipy/stats/stats.py	2010-11-20 18:19:28 UTC (rev 6934)
@@ -1491,7 +1491,7 @@
     elif kind == 'mean':
         return (sum(a < score) + sum(a <= score)) * 50 / float(n)
     else:
-        raise ValueError, "kind can only be 'rank', 'strict', 'weak' or 'mean'"
+        raise ValueError("kind can only be 'rank', 'strict', 'weak' or 'mean'")
 
 
 def histogram2(a, bins):
@@ -1668,7 +1668,7 @@
         if v[j] - np.mean(nargs[j]) > TINY:
             check = 0
     if check != 1:
-        raise ValueError, 'Lack of convergence in obrientransform.'
+        raise ValueError('Lack of convergence in obrientransform.')
     else:
         return array(nargs)
 
@@ -2115,7 +2115,7 @@
     lowercut = int(proportiontocut*len(a))
     uppercut = len(a) - lowercut
     if (lowercut >= uppercut):
-        raise ValueError, "Proportion too big."
+        raise ValueError("Proportion too big.")
     return a[lowercut:uppercut]
 
 
@@ -2218,7 +2218,7 @@
         y = np.transpose(y)
     N = m.shape[0]
     if (y.shape[0] != N):
-        raise ValueError, "x and y must have the same number of observations."
+        raise ValueError("x and y must have the same number of observations.")
     m = m - np.mean(m,axis=0)
     y = y - np.mean(y,axis=0)
     if bias:
@@ -3050,7 +3050,7 @@
     """
     a, b, axis = _chk2_asarray(a, b, axis)
     if a.shape[axis] != b.shape[axis]:
-        raise ValueError, 'unequal length arrays'
+        raise ValueError('unequal length arrays')
     n = a.shape[axis]
     df = float(n-1)
 
@@ -3201,7 +3201,7 @@
             cdf = getattr(distributions, rvs).cdf
             rvs = getattr(distributions, rvs).rvs
         else:
-            raise AttributeError, 'if rvs is string, cdf has to be the same distribution'
+            raise AttributeError('if rvs is string, cdf has to be the same distribution')
 
 
     if isinstance(cdf, basestring):
@@ -3427,7 +3427,7 @@
     #T = np.sqrt(tiecorrect(ranked))  # correction factor for tied scores
     T = tiecorrect(ranked)
     if T == 0:
-        raise ValueError, 'All numbers are identical in amannwhitneyu'
+        raise ValueError('All numbers are identical in amannwhitneyu')
     sd = np.sqrt(T*n1*n2*(n1+n2+1)/12.0)
 
     if use_continuity:
@@ -3565,7 +3565,7 @@
     h = 12.0 / (totaln*(totaln+1)) * ssbn - 3*(totaln+1)
     df = len(args) - 1
     if T == 0:
-        raise ValueError, 'All numbers are identical in kruskal'
+        raise ValueError('All numbers are identical in kruskal')
     h = h / float(T)
     return h, chisqprob(h,df)
 
@@ -3608,11 +3608,11 @@
     """
     k = len(args)
     if k < 3:
-        raise ValueError, '\nLess than 3 levels.  Friedman test not appropriate.\n'
+        raise ValueError('\nLess than 3 levels.  Friedman test not appropriate.\n')
     n = len(args[0])
     for i in range(1,k):
         if len(args[i]) <> n:
-            raise ValueError, 'Unequal N in friedmanchisquare.  Aborting.'
+            raise ValueError('Unequal N in friedmanchisquare.  Aborting.')
 
     # Rank data
     data = apply(_support.abut,args)

Modified: trunk/scipy/stats/tests/test_fit.py
===================================================================
--- trunk/scipy/stats/tests/test_fit.py	2010-11-20 18:13:28 UTC (rev 6933)
+++ trunk/scipy/stats/tests/test_fit.py	2010-11-20 18:19:28 UTC (rev 6934)
@@ -47,7 +47,7 @@
     diffthreshold[-2] = np.max([np.abs(rvs.mean())*thresh_percent,thresh_min])
     
     if np.any(np.isnan(est)):
-        raise AssertionError, 'nan returned in fit'
+        raise AssertionError('nan returned in fit')
     else:  
         if np.any((np.abs(diff) - diffthreshold) > 0.0):
 ##            txt = 'WARNING - diff too large with small sample'
@@ -60,7 +60,7 @@
                 txt  = 'parameter: %s\n' % str(truearg)
                 txt += 'estimated: %s\n' % str(est)
                 txt += 'diff     : %s\n' % str(diff)
-                raise AssertionError, 'fit not very good in %s\n' % distfn.name + txt
+                raise AssertionError('fit not very good in %s\n' % distfn.name + txt)
                 
 
 



More information about the Scipy-svn mailing list