[Scipy-svn] r6760 - in trunk: scipy/stats scipy/stats/tests tools
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat Sep 11 21:00:29 EDT 2010
Author: ptvirtan
Date: 2010-09-11 20:00:29 -0500 (Sat, 11 Sep 2010)
New Revision: 6760
Modified:
trunk/scipy/stats/_support.py
trunk/scipy/stats/distributions.py
trunk/scipy/stats/morestats.py
trunk/scipy/stats/stats.py
trunk/scipy/stats/tests/test_discrete_basic.py
trunk/scipy/stats/tests/test_stats.py
trunk/tools/py3tool.py
Log:
3K: stats: minimal changes to make scipy.stats to import
Modified: trunk/scipy/stats/_support.py
===================================================================
--- trunk/scipy/stats/_support.py 2010-09-12 01:00:08 UTC (rev 6759)
+++ trunk/scipy/stats/_support.py 2010-09-12 01:00:29 UTC (rev 6760)
@@ -1,9 +1,11 @@
from numpy import asarray
-import stats
import numpy as np
-from types import ListType, TupleType, StringType
import copy
+ListType = list
+TupleType = tuple
+StringType = str
+
def abut(source, *args):
# comment: except for the repetition, this is equivalent to hstack.
"""\nLike the |Stat abut command. It concatenates two arrays column-wise
@@ -236,7 +238,7 @@
item.append(cfcn(avgcol))
if stderr:
if len(avgcol)>1:
- item.append(stats.stderr(avgcol))
+ item.append(compute_stderr(avgcol))
else:
item.append('N/A')
if ns:
@@ -248,7 +250,30 @@
new_a = np.array(newlist,'O')
return new_a
+def _chk_asarray(a, axis):
+ if axis is None:
+ a = np.ravel(a)
+ outaxis = 0
+ else:
+ a = np.asarray(a)
+ outaxis = axis
+ return a, outaxis
+def _chk2_asarray(a, b, axis):
+ if axis is None:
+ a = np.ravel(a)
+ b = np.ravel(b)
+ outaxis = 0
+ else:
+ a = np.asarray(a)
+ b = np.asarray(b)
+ outaxis = axis
+ return a, b, outaxis
+
+def compute_stderr(a, axis=0, ddof=1):
+ a, axis = _chk_asarray(a, axis)
+ return np.std(a,axis,ddof=1) / float(np.sqrt(a.shape[axis]))
+
def makestr(item):
if type(item) != StringType:
item = str(item)
Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py 2010-09-12 01:00:08 UTC (rev 6759)
+++ trunk/scipy/stats/distributions.py 2010-09-12 01:00:29 UTC (rev 6760)
@@ -81,9 +81,15 @@
from scipy.misc import doccer
all = alltrue
sgf = vectorize
-import new
+try:
+ from new import instancemethod
+except ImportError:
+ # Python 3
+ def instancemethod(func, obj, cls):
+ return types.MethodType(func, obj)
+
# These are the docstring parts used for substitution in specific
# distribution docstrings.
@@ -266,9 +272,15 @@
# clean up all the separate docstring elements, we do not need them anymore
for obj in [s for s in dir() if s.startswith('_doc_')]:
exec('del ' + obj)
-del s, obj
+del obj
+try:
+ del s
+except NameError:
+ # in Python 3, loop variables are not visible after the loop
+ pass
+
def _build_random_array(fun, args, size=None):
# Build an array by applying function fun to
# the arguments in args, creating an array with
@@ -542,7 +554,7 @@
# self._size is total size of all output values
self._size = product(size, axis=0)
- if self._size > 1:
+ if self._size is not None and self._size > 1:
size = numpy.array(size, ndmin=1)
if np.all(scale == 0):
@@ -4764,17 +4776,17 @@
self.qvals = numpy.cumsum(self.pk,axis=0)
self.F = make_dict(self.xk, self.qvals)
self.Finv = reverse_dict(self.F)
- self._ppf = new.instancemethod(sgf(_drv_ppf,otypes='d'),
- self, rv_discrete)
- self._pmf = new.instancemethod(sgf(_drv_pmf,otypes='d'),
- self, rv_discrete)
- self._cdf = new.instancemethod(sgf(_drv_cdf,otypes='d'),
- self, rv_discrete)
- self._nonzero = new.instancemethod(_drv_nonzero, self, rv_discrete)
- self.generic_moment = new.instancemethod(_drv_moment,
- self, rv_discrete)
- self.moment_gen = new.instancemethod(_drv_moment_gen,
+ self._ppf = instancemethod(sgf(_drv_ppf,otypes='d'),
+ self, rv_discrete)
+ self._pmf = instancemethod(sgf(_drv_pmf,otypes='d'),
+ self, rv_discrete)
+ self._cdf = instancemethod(sgf(_drv_cdf,otypes='d'),
+ self, rv_discrete)
+ self._nonzero = instancemethod(_drv_nonzero, self, rv_discrete)
+ self.generic_moment = instancemethod(_drv_moment,
self, rv_discrete)
+ self.moment_gen = instancemethod(_drv_moment_gen,
+ self, rv_discrete)
self.numargs=0
else:
cdf_signature = inspect.getargspec(self._cdf.im_func)
@@ -4787,14 +4799,14 @@
#correct nin for generic moment vectorization
self.vec_generic_moment = sgf(_drv2_moment, otypes='d')
self.vec_generic_moment.nin = self.numargs + 2
- self.generic_moment = new.instancemethod(self.vec_generic_moment,
- self, rv_discrete)
+ self.generic_moment = instancemethod(self.vec_generic_moment,
+ self, rv_discrete)
#correct nin for ppf vectorization
_vppf = sgf(_drv2_ppfsingle,otypes='d')
_vppf.nin = self.numargs + 2 # +1 is for self
- self._vecppf = new.instancemethod(_vppf,
- self, rv_discrete)
+ self._vecppf = instancemethod(_vppf,
+ self, rv_discrete)
#now that self.numargs is defined, we can adjust nin
self._cdfvec.nin = self.numargs + 1
Modified: trunk/scipy/stats/morestats.py
===================================================================
--- trunk/scipy/stats/morestats.py 2010-09-12 01:00:08 UTC (rev 6759)
+++ trunk/scipy/stats/morestats.py 2010-09-12 01:00:29 UTC (rev 6760)
@@ -6,6 +6,7 @@
import math
import statlib
import stats
+from stats import find_repeats
import distributions
from numpy import isscalar, r_, log, sum, around, unique, asarray
from numpy import zeros, arange, sort, amin, amax, any, where, \
@@ -29,13 +30,7 @@
'circmean', 'circvar', 'circstd',
]
-def find_repeats(arr):
- """Find repeats in arr and return (repeats, repeat_count)
- """
- v1,v2, n = futil.dfreps(arr)
- return v1[:n],v2[:n]
-
##########################################################
### Bayesian confidence intervals for mean, variance, std
##########################################################
Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py 2010-09-12 01:00:08 UTC (rev 6759)
+++ trunk/scipy/stats/stats.py 2010-09-12 01:00:29 UTC (rev 6760)
@@ -203,12 +203,12 @@
import scipy.linalg as linalg
import numpy as np
-#import scipy.stats #is this a circular import ?
-from morestats import find_repeats #is only reference to scipy.stats
+import futil
import distributions
# Local imports.
import _support
+from _support import _chk_asarray, _chk2_asarray
__all__ = ['gmean', 'hmean', 'mean', 'cmedian', 'median', 'mode',
'tmean', 'tvar', 'tmin', 'tmax', 'tstd', 'tsem',
@@ -233,26 +233,12 @@
]
-def _chk_asarray(a, axis):
- if axis is None:
- a = np.ravel(a)
- outaxis = 0
- else:
- a = np.asarray(a)
- outaxis = axis
- return a, outaxis
+def find_repeats(arr):
+ """Find repeats in arr and return (repeats, repeat_count)
+ """
+ v1,v2, n = futil.dfreps(arr)
+ return v1[:n],v2[:n]
-def _chk2_asarray(a, b, axis):
- if axis is None:
- a = np.ravel(a)
- b = np.ravel(b)
- outaxis = 0
- else:
- a = np.asarray(a)
- b = np.asarray(b)
- outaxis = axis
- return a, b, outaxis
-
#######
### NAN friendly functions
########
@@ -1642,7 +1628,6 @@
a, axis = _chk_asarray(a, axis)
return np.std(a,axis,ddof=1) / float(np.sqrt(a.shape[axis]))
-
def sem(a, axis=0, ddof=1):
"""
Calculates the standard error of the mean (or standard error of
Modified: trunk/scipy/stats/tests/test_discrete_basic.py
===================================================================
--- trunk/scipy/stats/tests/test_discrete_basic.py 2010-09-12 01:00:08 UTC (rev 6759)
+++ trunk/scipy/stats/tests/test_discrete_basic.py 2010-09-12 01:00:29 UTC (rev 6760)
@@ -142,7 +142,7 @@
def check_oth(distfn, arg, msg):
#checking other methods of distfn
- meanint = round(distfn.stats(*arg)[0]) # closest integer to mean
+ meanint = round(float(distfn.stats(*arg)[0])) # closest integer to mean
npt.assert_almost_equal(distfn.sf(meanint, *arg), 1 - \
distfn.cdf(meanint, *arg), decimal=8)
median_sf = distfn.isf(0.5, *arg)
Modified: trunk/scipy/stats/tests/test_stats.py
===================================================================
--- trunk/scipy/stats/tests/test_stats.py 2010-09-12 01:00:08 UTC (rev 6759)
+++ trunk/scipy/stats/tests/test_stats.py 2010-09-12 01:00:29 UTC (rev 6760)
@@ -1572,7 +1572,7 @@
def do(self, a, b, axis=None, dtype=None):
x = stats.hmean(a, axis=axis, dtype=dtype)
assert_almost_equal(b, x)
- assert_equal(x.dtype, dtype)
+ assert_equal(x.dtype, dtype)
class GeoMeanTestCase:
def test_1dlist(self):
@@ -1663,7 +1663,7 @@
#Note this doesn't test when axis is not specified
x = stats.gmean(a, axis=axis, dtype=dtype)
assert_almost_equal(b, x)
- assert_equal(x.dtype, dtype)
+ assert_equal(x.dtype, dtype)
def test_binomtest():
Modified: trunk/tools/py3tool.py
===================================================================
--- trunk/tools/py3tool.py 2010-09-12 01:00:08 UTC (rev 6759)
+++ trunk/tools/py3tool.py 2010-09-12 01:00:29 UTC (rev 6760)
@@ -173,6 +173,7 @@
os.path.join('optimize', 'nnls.py'),
os.path.join('signal', '__init__.py'),
os.path.join('signal', 'bsplines.py'),
+ os.path.join('signal', 'signaltools.py'),
os.path.join('special', '__init__.py'),
os.path.join('special', 'basic.py'),
os.path.join('special', 'orthogonal.py'),
@@ -184,6 +185,11 @@
os.path.join('sparse', 'linalg', 'eigen', 'arpack', 'arpack.py'),
os.path.join('sparse', 'linalg', 'eigen', 'arpack', 'speigs.py'),
os.path.join('sparse', 'linalg', 'iterative', 'isolve', 'iterative.py'),
+ os.path.join('stats', 'stats.py'),
+ os.path.join('stats', 'distributions.py'),
+ os.path.join('stats', 'morestats.py'),
+ os.path.join('stats', 'kde.py'),
+ os.path.join('stats', 'mstats_basic.py'),
]
if any(filename.endswith(x) for x in import_mangling):
More information about the Scipy-svn
mailing list