diff options
author | Jarrod Millman <millman@berkeley.edu> | 2008-08-08 04:33:45 +0000 |
---|---|---|
committer | Jarrod Millman <millman@berkeley.edu> | 2008-08-08 04:33:45 +0000 |
commit | 70ed0f238156680efba9b4028810f3aed486357b (patch) | |
tree | e5e0f42e586156ed74128cff0fe84404398b918b | |
parent | 0da812e06828be6749b1840b48c4f100dc3dfd68 (diff) | |
download | numpy-70ed0f238156680efba9b4028810f3aed486357b.tar.gz |
ran reindent
50 files changed, 228 insertions, 248 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index 6c9493fc0..66f80040c 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -160,4 +160,3 @@ else: __all__.extend(core.__all__) __all__.extend(lib.__all__) __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma', 'doc']) - diff --git a/numpy/core/code_generators/docstrings.py b/numpy/core/code_generators/docstrings.py index e6e6ab0f2..7271a509d 100644 --- a/numpy/core/code_generators/docstrings.py +++ b/numpy/core/code_generators/docstrings.py @@ -2234,4 +2234,3 @@ add_newdoc('numpy.core.umath', 'true_divide', equivalent to true division in Python. """) - diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 40f14cd79..449754f87 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1778,7 +1778,7 @@ class errstate(object): """with errstate(**state): --> operations in following block use given state. # Set error handling to known state. - >>> _ = np.seterr(invalid='raise', divide='raise', over='raise', + >>> _ = np.seterr(invalid='raise', divide='raise', over='raise', ... under='ignore') >>> a = -np.arange(3) diff --git a/numpy/core/records.py b/numpy/core/records.py index 545330a30..6f94c3e9f 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -551,7 +551,7 @@ def fromrecords(recList, dtype=None, shape=None, formats=None, names=None, >>> r.col1 array([456, 2]) >>> r.col2 - chararray(['dbe', 'de'], + chararray(['dbe', 'de'], dtype='|S3') >>> import cPickle >>> print cPickle.loads(cPickle.dumps(r)) @@ -639,7 +639,7 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None, >>> a.tofile(fd) >>> >>> fd.seek(0) - >>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10, + >>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10, ... byteorder='<') >>> print r[5] (0.5, 10, 'abcde') diff --git a/numpy/core/scons_support.py b/numpy/core/scons_support.py index c4a0ef6de..d8190537a 100644 --- a/numpy/core/scons_support.py +++ b/numpy/core/scons_support.py @@ -185,7 +185,7 @@ def define_no_smp(): array_api_gen_bld = Builder(action = Action(do_generate_numpy_api, '$ARRAPIGENCOMSTR'), emitter = generate_api_emitter) - + ufunc_api_gen_bld = Builder(action = Action(do_generate_ufunc_api, '$UFUNCAPIGENCOMSTR'), emitter = generate_api_emitter) diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 1f4f23d82..531df6a2e 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -190,7 +190,7 @@ def configuration(parent_package='',top_path=None): "See previous error messages for more information." moredefs = [] - + # Check wether we can use inttypes (C99) formats if config_cmd.check_decl('PRIdPTR', headers = ['inttypes.h']): moredefs.append(('NPY_USE_C99_FORMATS', 1)) diff --git a/numpy/core/setupscons.py b/numpy/core/setupscons.py index 322b341e3..be42246ad 100644 --- a/numpy/core/setupscons.py +++ b/numpy/core/setupscons.py @@ -51,7 +51,7 @@ def configuration(parent_package='',top_path=None): # XXX: I really have to think about how to communicate path info # between scons and distutils, and set the options at one single # location. - target = join(get_scons_pkg_build_dir(config.name), + target = join(get_scons_pkg_build_dir(config.name), 'include/numpy/numpyconfig.h') incl_dir = os.path.dirname(target) if incl_dir not in config.numpy_include_dirs: diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py index 8abeccc6c..8fa189df4 100644 --- a/numpy/core/tests/test_defchararray.py +++ b/numpy/core/tests/test_defchararray.py @@ -47,7 +47,7 @@ class TestOperations(TestCase): # [A[1,0]*r, A[1,1]*r]]).view(np.chararray) # # assert all(Ar == (self.A * r)) - + for ob in [object(), 'qrs']: try: A * ob @@ -63,7 +63,7 @@ class TestOperations(TestCase): # [A[1,0]*r, A[1,1]*r]]).view(np.chararray) # # assert all(Ar == (r * self.A)) - + for ob in [object(), 'qrs']: try: ob * A @@ -78,7 +78,7 @@ class TestOperations(TestCase): def test_rmod(self): assert ("%s" % self.A) == str(self.A) assert ("%r" % self.A) == repr(self.A) - + for ob in [42, object()]: try: ob % self.A diff --git a/numpy/core/tests/test_defmatrix.py b/numpy/core/tests/test_defmatrix.py index 8e28dcbe1..87dc8596c 100644 --- a/numpy/core/tests/test_defmatrix.py +++ b/numpy/core/tests/test_defmatrix.py @@ -200,7 +200,7 @@ class TestAlgebra(TestCase): mA2 = matrix(A) mA2 *= 3 assert allclose(mA2.A, 3*A) - + def test_notimplemented(self): '''Check that 'not implemented' operations produce a failure.''' A = matrix([[1., 2.], diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py index 32c01621e..9d940ede9 100644 --- a/numpy/core/tests/test_memmap.py +++ b/numpy/core/tests/test_memmap.py @@ -48,4 +48,3 @@ class TestMemmap(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 83aaf5f45..126ed1973 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -887,4 +887,3 @@ class TestLikeFuncs(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py index f8ffddbd7..745f48737 100644 --- a/numpy/core/tests/test_numerictypes.py +++ b/numpy/core/tests/test_numerictypes.py @@ -252,7 +252,7 @@ class read_values_nested: self._buffer[1][4]], dtype='f8')) assert_equal(h['z'], np.array([self._buffer[0][5], self._buffer[1][5]], dtype='u1')) - + def test_nested1_acessors(self): """Check reading the nested fields of a nested array (1st level)""" @@ -356,4 +356,3 @@ class TestCommonType(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index 8239da5c7..85306b1af 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -57,7 +57,7 @@ class TestFromrecords(TestCase): y = eval("np." + repr(x)) assert isinstance(y, np.recarray) assert_equal(y, x) - + def test_recarray_from_names(self): ra = np.rec.array([ (1, 'abc', 3.7000002861022949, 0), @@ -130,4 +130,3 @@ def test_find_duplicate(): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index aa924fac8..33d12b61c 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1070,9 +1070,9 @@ class TestRegression(TestCase): dat = TestArray([[1,2,3,4],[5,6,7,8]],'jubba') assert dat.info == 'jubba' dat.resize((4,2)) - assert dat.info == 'jubba' + assert dat.info == 'jubba' dat.sort() - assert dat.info == 'jubba' + assert dat.info == 'jubba' dat.fill(2) assert dat.info == 'jubba' dat.put([2,3,4],[6,3,4]) diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py index 1b1fc7b2d..bb1ada66b 100644 --- a/numpy/core/tests/test_scalarmath.py +++ b/numpy/core/tests/test_scalarmath.py @@ -86,7 +86,7 @@ class TestRepr(TestCase): last_exponent_bit_idx = finfo.nexp storage_bytes = np.dtype(t).itemsize*8 # could add some more types to the list below - for which in ['small denorm','small norm']: + for which in ['small denorm','small norm']: # Values from http://en.wikipedia.org/wiki/IEEE_754 constr = np.array([0x00]*storage_bytes,dtype=np.uint8) if which == 'small denorm': diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index eda52f961..0f5a3365c 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -211,11 +211,11 @@ class TestComplexFunctions(object): yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1 - + yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, -1j], 1, -1 yield _check_branch_cut, np.arccos, [ -2, 2], [1j, -1j], 1, -1 yield _check_branch_cut, np.arctan, [-2j, 2j], [1, -1 ], -1, 1 - + yield _check_branch_cut, np.arcsinh, [-2j, 2j], [-1, 1], -1, 1 yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1 yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, -1j], 1, -1 @@ -239,7 +239,7 @@ class TestComplexFunctions(object): yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, -1j], 1, -1, True test_branch_cuts_failing = dec.skipknownfailure(test_branch_cuts_failing) - + def test_against_cmath(self): import cmath, sys @@ -248,7 +248,7 @@ class TestComplexFunctions(object): broken_cmath_asinh = False if sys.version_info < (2,5,3): broken_cmath_asinh = True - + points = [-2, 2j, 2, -2j, -1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} @@ -261,20 +261,20 @@ class TestComplexFunctions(object): for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) - + if cname == 'asinh' and broken_cmath_asinh: - continue + continue assert abs(a - b) < atol, "%s %s: %s; cmath: %s"%(fname,p,a,b) class TestC99(object): """Check special functions at special points against the C99 standard""" # NB: inherits from object instead of TestCase since using test generators - + # # Non-conforming results are with XXX added to the exception field. # - + def test_clog(self): for p, v, e in [ ((-0., 0.), (-inf, pi), 'divide'), @@ -292,7 +292,7 @@ class TestC99(object): ((+nan, nan), (nan, nan), 'XXX'), # raises 'invalid' on some platfs ]: yield self._check, np.log, p, v, e - + def test_csqrt(self): for p, v, e in [ ((-0., 0.), (0.,0.), 'XXX'), # now (-0., 0.) @@ -391,7 +391,7 @@ class TestC99(object): got = "(%s, %s)" % (repr(got.real), repr(got.imag)) expected = "(%s, %s)" % (repr(value.real), repr(value.imag)) assert got == expected, (got, expected) - + # check exceptions if exc in ('divide', 'invalid', 'over', 'under'): v[exc] = 'raise' @@ -442,24 +442,24 @@ def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False, """ x0 = np.atleast_1d(x0).astype(dtype) dx = np.atleast_1d(dx).astype(dtype) - + scale = np.finfo(dtype).eps * 1e3 atol = 1e-4 - + y0 = f(x0) yp = f(x0 + dx*scale*np.absolute(x0)/np.absolute(dx)) ym = f(x0 - dx*scale*np.absolute(x0)/np.absolute(dx)) - + assert np.all(np.absolute(y0.real - yp.real) < atol), (y0, yp) assert np.all(np.absolute(y0.imag - yp.imag) < atol), (y0, yp) assert np.all(np.absolute(y0.real - ym.real*re_sign) < atol), (y0, ym) assert np.all(np.absolute(y0.imag - ym.imag*im_sign) < atol), (y0, ym) - + if sig_zero_ok: # check that signed zeros also work as a displacement jr = (x0.real == 0) & (dx.real != 0) ji = (x0.imag == 0) & (dx.imag != 0) - + x = -x0 x.real[jr] = 0.*dx.real x.imag[ji] = 0.*dx.imag diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py index 3d7492414..4968b28ac 100644 --- a/numpy/core/tests/test_unicode.py +++ b/numpy/core/tests/test_unicode.py @@ -214,31 +214,31 @@ class test_assign_values_1_ucs4(assign_values, TestCase): """Check the assignment of valued arrays (size 1, UCS4 values)""" ulen = 1 ucs_value = ucs4_value - + class test_assign_values_2_ucs2(assign_values, TestCase): """Check the assignment of valued arrays (size 2, UCS2 values)""" ulen = 2 ucs_value = ucs2_value - + class test_assign_values_2_ucs4(assign_values, TestCase): """Check the assignment of valued arrays (size 2, UCS4 values)""" ulen = 2 ucs_value = ucs4_value - + class test_assign_values_1009_ucs2(assign_values, TestCase): """Check the assignment of valued arrays (size 1009, UCS2 values)""" ulen = 1009 ucs_value = ucs2_value - + class test_assign_values_1009_ucs4(assign_values, TestCase): """Check the assignment of valued arrays (size 1009, UCS4 values)""" ulen = 1009 ucs_value = ucs4_value - + ############################################################ @@ -286,31 +286,31 @@ class test_byteorder_1_ucs2(byteorder_values, TestCase): """Check the byteorder in unicode (size 1, UCS2 values)""" ulen = 1 ucs_value = ucs2_value - + class test_byteorder_1_ucs4(byteorder_values, TestCase): """Check the byteorder in unicode (size 1, UCS4 values)""" ulen = 1 ucs_value = ucs4_value - + class test_byteorder_2_ucs2(byteorder_values, TestCase): """Check the byteorder in unicode (size 2, UCS2 values)""" ulen = 2 ucs_value = ucs2_value - + class test_byteorder_2_ucs4(byteorder_values, TestCase): """Check the byteorder in unicode (size 2, UCS4 values)""" ulen = 2 ucs_value = ucs4_value - + class test_byteorder_1009_ucs2(byteorder_values, TestCase): """Check the byteorder in unicode (size 1009, UCS2 values)""" ulen = 1009 ucs_value = ucs2_value - + class test_byteorder_1009_ucs4(byteorder_values, TestCase): """Check the byteorder in unicode (size 1009, UCS4 values)""" @@ -320,4 +320,3 @@ class test_byteorder_1009_ucs4(byteorder_values, TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/distutils/command/scons.py b/numpy/distutils/command/scons.py index a4768248e..b867080b6 100644 --- a/numpy/distutils/command/scons.py +++ b/numpy/distutils/command/scons.py @@ -125,7 +125,7 @@ def dist2sconscxx(compiler): (C++ compiler). The argument should be a Compiler instance.""" if compiler.compiler_type == 'msvc': return compiler.compiler_type - + return compiler.compiler_cxx[0] def get_compiler_executable(compiler): @@ -368,7 +368,7 @@ class scons(old_build_ext): raise RuntimeError("You need numscons >= %s to build numpy "\ "with numscons (detected %s )" \ % (minver, get_version())) - + else: # nothing to do, just leave it here. return diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 15bced235..23848b72a 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -1190,7 +1190,7 @@ class Configuration(object): pre_hook and post hook should be sequences of callable, which will be use before and after executing scons. The callable should be defined as callable(*args, **kw). It is ugly, but well, hooks are ugly anyway... - + sconscript can be None, which can be useful to add only post/pre hooks.""" if standalone: diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py index f1b9cd2cf..ba353a093 100644 --- a/numpy/lib/__init__.py +++ b/numpy/lib/__init__.py @@ -39,4 +39,3 @@ __all__ += financial.__all__ from numpy.testing import Tester test = Tester().test bench = Tester().bench - diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 8bd76d17f..cd9a87931 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -330,4 +330,3 @@ def setdiff1d(ar1, ar2): return aux else: return np.asarray(ar1)[aux == 0] - diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 686db237a..75143d70d 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -200,14 +200,14 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, new=None): a : array_like Input data. bins : int or sequence of scalars, optional - If `bins` is an int, it defines the number of equal-width + If `bins` is an int, it defines the number of equal-width bins in the given range (10, by default). If `bins` is a sequence, - it defines the bin edges, including the rightmost edge, allowing + it defines the bin edges, including the rightmost edge, allowing for non-uniform bin widths. range : (float, float), optional The lower and upper range of the bins. If not provided, range is simply ``(a.min(), a.max())``. Values outside the range are - ignored. Note that with `new` set to False, values below + ignored. Note that with `new` set to False, values below the range are ignored, while those above the range are tallied in the rightmost bin. normed : bool, optional @@ -224,10 +224,10 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, new=None): so that the integral of the density over the range remains 1. The `weights` keyword is only available with `new` set to True. new : {None, True, False}, optional - Whether to use the new semantics for histogram: + Whether to use the new semantics for histogram: * None : the new behaviour is used, and a warning is printed, * True : the new behaviour is used and no warning is printed, - * False : the old behaviour is used and a message is printed + * False : the old behaviour is used and a message is printed warning about future deprecation. Returns @@ -264,18 +264,18 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, new=None): # Old behavior if new == False: warnings.warn(""" - The original semantics of histogram is scheduled to be - deprecated in NumPy 1.3. The new semantics fixes + The original semantics of histogram is scheduled to be + deprecated in NumPy 1.3. The new semantics fixes long-standing issues with outliers handling. The main - changes concern - 1. the definition of the bin edges, - now including the rightmost edge, and - 2. the handling of upper outliers, - now ignored rather than tallied in the rightmost bin. - + changes concern + 1. the definition of the bin edges, + now including the rightmost edge, and + 2. the handling of upper outliers, + now ignored rather than tallied in the rightmost bin. + Please read the docstring for more information. """, Warning) - + a = asarray(a).ravel() if (range is not None): @@ -326,19 +326,19 @@ def histogram(a, bins=10, range=None, normed=False, weights=None, new=None): warnings.warn(""" The semantics of histogram has been modified in the current release to fix long-standing issues with - outliers handling. The main changes concern - 1. the definition of the bin edges, - now including the rightmost edge, and + outliers handling. The main changes concern + 1. the definition of the bin edges, + now including the rightmost edge, and 2. the handling of upper outliers, now ignored rather - than tallied in the rightmost bin. - The previous behaviour is still accessible using - `new=False`, but is scheduled to be deprecated in the - next release (1.3). - + than tallied in the rightmost bin. + The previous behaviour is still accessible using + `new=False`, but is scheduled to be deprecated in the + next release (1.3). + *This warning will not printed in the 1.3 release.* - - Use `new=True` to bypass this warning. - + + Use `new=True` to bypass this warning. + Please read the docstring for more information. """, Warning) a = asarray(a) diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py index 8006b25d1..c7a953491 100644 --- a/numpy/lib/stride_tricks.py +++ b/numpy/lib/stride_tricks.py @@ -105,7 +105,6 @@ def broadcast_arrays(*args): common_shape.append(1) # Construct the new arrays. - broadcasted = [as_strided(x, shape=sh, strides=st) for (x,sh,st) in + broadcasted = [as_strided(x, shape=sh, strides=st) for (x,sh,st) in zip(args, shapes, strides)] return broadcasted - diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index c9e9b2eee..95a72f76a 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -318,4 +318,3 @@ class TestOpenFunc(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index 37a052861..474842c8a 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -16,7 +16,7 @@ class TestAso(TestCase): d, c = unique1d( a, True ) ed = np.array( [2, 3, 0, 1] ) - + assert_array_equal( d,ed ) assert_array_equal( c, ec ) diff --git a/numpy/lib/tests/test_financial.py b/numpy/lib/tests/test_financial.py index d66430542..1ac14b561 100644 --- a/numpy/lib/tests/test_financial.py +++ b/numpy/lib/tests/test_financial.py @@ -3,7 +3,7 @@ import numpy as np class TestFinancial(TestCase): def test_rate(self): - assert_almost_equal(np.rate(10,0,-3500,10000), + assert_almost_equal(np.rate(10,0,-3500,10000), 0.1107, 4) def test_irr(self): @@ -12,7 +12,7 @@ class TestFinancial(TestCase): 0.0524, 2) def test_pv(self): - assert_almost_equal(np.pv(0.07,20,12000,0), + assert_almost_equal(np.pv(0.07,20,12000,0), -127128.17, 2) def test_fv(self): diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 6e1c3583d..268d0a943 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -297,7 +297,7 @@ class TestGradient(TestCase): def test_badargs(self): # for 2D array, gradient can take 0,1, or 2 extra args x = array([[1,1],[3,4]]) - assert_raises(SyntaxError, gradient, x, array([1.,1.]), + assert_raises(SyntaxError, gradient, x, array([1.,1.]), array([1.,1.]), array([1.,1.])) class TestAngle(TestCase): @@ -441,7 +441,7 @@ class TestSinc(TestCase): class TestHistogram(TestCase): def setUp(self): warnings.simplefilter('ignore', Warning) - + def tearDown(self): warnings.resetwarnings() @@ -658,60 +658,60 @@ class TestNaNFuncts(TestCase): def test_nansum(self): assert_almost_equal(nansum(self.A), 8.0664079100000006) - assert_almost_equal(nansum(self.A,0), + assert_almost_equal(nansum(self.A,0), array([[ 1.32229056, 0.92403798, 0.39531816], [ 0.96090861, 1.26908897, 0.99071783], [ 0.98877405, 0.53370154, 0.68157021]])) - assert_almost_equal(nansum(self.A,1), + assert_almost_equal(nansum(self.A,1), array([[ 0.40037675, 0.17621204, 0.76778851], [ 1.30085304, 0.87964135, 0.72217448], [ 1.57074343, 1.6709751 , 0.57764321]])) - assert_almost_equal(nansum(self.A,2), + assert_almost_equal(nansum(self.A,2), array([[ 0.02940178, 0.86861904, 0.44635648], [ 0.97452409, 0.87964135, 1.04850343], [ 1.63772083, 1.47245502, 0.70918589]])) - + def test_nanmin(self): assert_almost_equal(nanmin(self.A), 0.01319214) - assert_almost_equal(nanmin(self.A,0), + assert_almost_equal(nanmin(self.A,0), array([[ 0.59541557, 0.01319214, 0.01620964], [ 0.11704017, 0.38944762, 0.23913896], [ 0.28333658, 0.1630199 , 0.33850425]])) - assert_almost_equal(nanmin(self.A,1), + assert_almost_equal(nanmin(self.A,1), array([[ 0.11704017, 0.01319214, 0.01620964], [ 0.59541557, 0.87964135, 0.34306596], [ 0.72687499, 0.37068164, 0.23913896]])) - assert_almost_equal(nanmin(self.A,2), + assert_almost_equal(nanmin(self.A,2), array([[ 0.01319214, 0.11704017, 0.1630199 ], [ 0.37910852, 0.87964135, 0.34306596], [ 0.72687499, 0.23913896, 0.33850425]])) def test_nanargmin(self): assert_almost_equal(nanargmin(self.A), 1) - assert_almost_equal(nanargmin(self.A,0), + assert_almost_equal(nanargmin(self.A,0), array([[1, 0, 0], [0, 2, 2], [0, 0, 2]])) - assert_almost_equal(nanargmin(self.A,1), + assert_almost_equal(nanargmin(self.A,1), array([[1, 0, 0], [0, 1, 2], [0, 2, 1]])) - assert_almost_equal(nanargmin(self.A,2), + assert_almost_equal(nanargmin(self.A,2), array([[1, 0, 1], [2, 1, 2], [0, 2, 2]])) def test_nanmax(self): assert_almost_equal(nanmax(self.A), 0.91084584000000002) - assert_almost_equal(nanmax(self.A,0), + assert_almost_equal(nanmax(self.A,0), array([[ 0.72687499, 0.91084584, 0.37910852], [ 0.84386844, 0.87964135, 0.75157887], [ 0.70543747, 0.37068164, 0.34306596]])) - assert_almost_equal(nanmax(self.A,1), + assert_almost_equal(nanmax(self.A,1), array([[ 0.28333658, 0.1630199 , 0.75157887], [ 0.70543747, 0.87964135, 0.37910852], [ 0.84386844, 0.91084584, 0.33850425]])) - assert_almost_equal(nanmax(self.A,2), + assert_almost_equal(nanmax(self.A,2), array([[ 0.01620964, 0.75157887, 0.28333658], [ 0.59541557, 0.87964135, 0.70543747], [ 0.91084584, 0.84386844, 0.37068164]])) @@ -725,22 +725,22 @@ class TestCorrCoef(TestCase): B = array([[ 0.10377691, 0.5417086 , 0.49807457], [ 0.82872117, 0.77801674, 0.39226705], [ 0.9314666 , 0.66800209, 0.03538394]]) - assert_almost_equal(corrcoef(A), + assert_almost_equal(corrcoef(A), array([[ 1. , 0.9379533 , -0.04931983], [ 0.9379533 , 1. , 0.30007991], [-0.04931983, 0.30007991, 1. ]])) - assert_almost_equal(corrcoef(A,B), - array([[ 1. , 0.9379533 , -0.04931983, + assert_almost_equal(corrcoef(A,B), + array([[ 1. , 0.9379533 , -0.04931983, 0.30151751, 0.66318558, 0.51532523], - [ 0.9379533 , 1. , 0.30007991, + [ 0.9379533 , 1. , 0.30007991, -0.04781421, 0.88157256, 0.78052386], [-0.04931983, 0.30007991, 1. , -0.96717111, 0.71483595, 0.83053601], - [ 0.30151751, -0.04781421, -0.96717111, + [ 0.30151751, -0.04781421, -0.96717111, 1. , -0.51366032, -0.66173113], - [ 0.66318558, 0.88157256, 0.71483595, + [ 0.66318558, 0.88157256, 0.71483595, -0.51366032, 1. , 0.98317823], - [ 0.51532523, 0.78052386, 0.83053601, + [ 0.51532523, 0.78052386, 0.83053601, -0.66173113, 0.98317823, 1. ]])) @@ -749,7 +749,7 @@ class Test_i0(TestCase): def test_simple(self): assert_almost_equal(i0(0.5), array(1.0634833707413234)) A = array([ 0.49842636, 0.6969809 , 0.22011976, 0.0155549]) - assert_almost_equal(i0(A), + assert_almost_equal(i0(A), array([ 1.06307822, 1.12518299, 1.01214991, 1.00006049])) B = array([[ 0.827002 , 0.99959078], [ 0.89694769, 0.39298162], @@ -768,11 +768,11 @@ class TestKaiser(TestCase): assert_almost_equal(kaiser(0,1.0), array([])) assert isnan(kaiser(1,1.0)) assert_almost_equal(kaiser(2,1.0), array([ 0.78984831, 0.78984831])) - assert_almost_equal(kaiser(5,1.0), - array([ 0.78984831, 0.94503323, 1. , + assert_almost_equal(kaiser(5,1.0), + array([ 0.78984831, 0.94503323, 1. , 0.94503323, 0.78984831])) - assert_almost_equal(kaiser(5,1.56789), - array([ 0.58285404, 0.88409679, 1. , + assert_almost_equal(kaiser(5,1.56789), + array([ 0.58285404, 0.88409679, 1. , 0.88409679, 0.58285404])) class TestMsort(TestCase): diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index 3cfed1059..47529502d 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -64,4 +64,3 @@ class TestConcatenator(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index c6a8498eb..1d2c2321a 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -57,7 +57,7 @@ class TestSavezLoad(RoundtripTest, TestCase): l = np.load(c) assert_equal(a, l['file_a']) assert_equal(b, l['file_b']) - + class TestSaveTxt(TestCase): def test_array(self): @@ -220,8 +220,8 @@ class TestLoadTxt(TestCase): c.seek(0) x = np.loadtxt(c, dtype=float, usecols=(1,2)) assert_array_equal(x, a[:,1:]) - - # Checking with dtypes defined converters. + + # Checking with dtypes defined converters. data = '''JOE 70.1 25.3 BOB 60.5 27.9 ''' diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py index 406c151a1..96dd084b2 100644 --- a/numpy/lib/tests/test_polynomial.py +++ b/numpy/lib/tests/test_polynomial.py @@ -77,7 +77,7 @@ from numpy.testing import * import numpy as np class TestDocs(TestCase): - def test_doctests(self): + def test_doctests(self): return rundocs() def test_roots(self): @@ -113,4 +113,3 @@ class TestDocs(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py index 7d7db93e4..189b2e481 100644 --- a/numpy/lib/tests/test_regression.py +++ b/numpy/lib/tests/test_regression.py @@ -28,4 +28,3 @@ class TestRegression(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py index a4e771876..59c48dba0 100644 --- a/numpy/lib/tests/test_shape_base.py +++ b/numpy/lib/tests/test_shape_base.py @@ -13,7 +13,7 @@ class TestApplyAlongAxis(TestCase): def test_3d(self): a = arange(27).reshape((3,3,3)) - assert_array_equal(apply_along_axis(sum,0,a), + assert_array_equal(apply_along_axis(sum,0,a), [[27,30,33],[36,39,42],[45,48,51]]) diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py index 2dd3f3365..32c4ca58e 100644 --- a/numpy/lib/tests/test_twodim_base.py +++ b/numpy/lib/tests/test_twodim_base.py @@ -195,4 +195,3 @@ class TestTri(TestCase): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py index a7fbccea1..bd941adad 100644 --- a/numpy/lib/tests/test_ufunclike.py +++ b/numpy/lib/tests/test_ufunclike.py @@ -65,4 +65,3 @@ def test(): if __name__ == "__main__": run_module_suite() - diff --git a/numpy/ma/core.py b/numpy/ma/core.py index ec7d8de57..0b5372fa3 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -44,7 +44,7 @@ __all__ = ['MAError', 'MaskType', 'MaskedArray', 'masked_less','masked_less_equal', 'masked_not_equal', 'masked_object','masked_outside', 'masked_print_option', 'masked_singleton','masked_values', 'masked_where', 'max', 'maximum', - 'maximum_fill_value', 'mean', 'min', 'minimum', 'minimum_fill_value', + 'maximum_fill_value', 'mean', 'min', 'minimum', 'minimum_fill_value', 'multiply', 'negative', 'nomask', 'nonzero', 'not_equal', 'ones', 'outer', 'outerproduct', @@ -740,7 +740,7 @@ fmod = _DomainedBinaryOperation(umath.fmod, _DomainSafeDivide(), 0, 1) def make_mask_descr(ndtype): """Constructs a dtype description list from a given dtype. Each field is set to a bool. - + """ if ndtype.names: mdescr = [list(_) for _ in ndtype.descr] @@ -2155,13 +2155,13 @@ masked_%(name)s(data = %(data)s, #............................................ def all(self, axis=None, out=None): """a.all(axis=None, out=None) - + Check if all of the elements of `a` are true. Performs a logical_and over the given axis and returns the result. Masked values are considered as True during computation. For convenience, the output array is masked where ALL the values along the - current axis are masked: if the output would have been a scalar and that + current axis are masked: if the output would have been a scalar and that all the values are masked, then the output is `masked`. Parameters @@ -2176,7 +2176,7 @@ masked_%(name)s(data = %(data)s, See Also -------- all : equivalent function - + Example ------- >>> np.ma.array([1,2,3]).all() @@ -2327,8 +2327,8 @@ masked_%(name)s(data = %(data)s, The cumulative sum is calculated over the flattened array by default, otherwise over the specified axis. - Masked values are set to 0 internally during the computation. - However, their position is saved, and the result will be masked at + Masked values are set to 0 internally during the computation. + However, their position is saved, and the result will be masked at the same locations. Parameters @@ -2456,8 +2456,8 @@ masked_%(name)s(data = %(data)s, The cumulative product is taken over the flattened array by default, otherwise over the specified axis. - Masked values are set to 1 internally during the computation. - However, their position is saved, and the result will be masked at + Masked values are set to 1 internally during the computation. + However, their position is saved, and the result will be masked at the same locations. Parameters @@ -2695,7 +2695,7 @@ masked_%(name)s(data = %(data)s, elements, N-ddof. The option ddof defaults to zero, that is, a biased estimate. Note that for complex numbers std takes the absolute value before squaring, so that the result is always real and nonnegative. - + """ dvar = self.var(axis=axis,dtype=dtype,out=out, ddof=ddof) if dvar is not masked: @@ -2781,11 +2781,11 @@ masked_%(name)s(data = %(data)s, If None, the index is into the flattened array, otherwise along the specified axis fill_value : {var}, optional - Value used to fill in the masked values. If None, the output of + Value used to fill in the masked values. If None, the output of minimum_fill_value(self._data) is used instead. out : {None, array}, optional Array into which the result can be placed. Its type is preserved - and it must be of the right shape to hold the output. + and it must be of the right shape to hold the output. """ if fill_value is None: @@ -2846,11 +2846,11 @@ masked_%(name)s(data = %(data)s, Sorting algorithm (default 'quicksort') Possible values: 'quicksort', 'mergesort', or 'heapsort'. order : {None, var} - If a has fields defined, then the order keyword can be the field name - to sort on or a list (or tuple) of field names to indicate the order + If a has fields defined, then the order keyword can be the field name + to sort on or a list (or tuple) of field names to indicate the order that fields should be used to define the sort. endwith : {True, False}, optional - Whether missing values (if any) should be forced in the upper indices + Whether missing values (if any) should be forced in the upper indices (at the end of the array) (True) or lower indices (at the beginning). fill_value : {var} Value used to fill in the masked values. If None, use @@ -3115,7 +3115,7 @@ masked_%(name)s(data = %(data)s, Warnings -------- - As for :meth:`ndarray.tostring`, information about the shape, dtype..., + As for :meth:`ndarray.tostring`, information about the shape, dtype..., but also fill_value will be lost. """ @@ -3128,12 +3128,12 @@ masked_%(name)s(data = %(data)s, """Transforms a masked array into a flexible-type array with two fields: * the ``_data`` field stores the ``_data`` part of the array; * the ``_mask`` field stores the ``_mask`` part of the array; - + Warnings -------- - A side-effect of transforming a masked array into a flexible ndarray is + A side-effect of transforming a masked array into a flexible ndarray is that metainformation (``fill_value``, ...) will be lost. - + """ # Get the basic dtype .... ddtype = self.dtype @@ -3322,7 +3322,7 @@ def min(obj, axis=None, out=None, fill_value=None): try: return obj.min(axis=axis, fill_value=fill_value, out=out) except (AttributeError, TypeError): - # If obj doesn't have a max method, + # If obj doesn't have a max method, # ...or if the method doesn't accept a fill_value argument return asanyarray(obj).min(axis=axis, fill_value=fill_value, out=out) min.__doc__ = MaskedArray.min.__doc__ @@ -3331,7 +3331,7 @@ def max(obj, axis=None, out=None, fill_value=None): try: return obj.max(axis=axis, fill_value=fill_value, out=out) except (AttributeError, TypeError): - # If obj doesn't have a max method, + # If obj doesn't have a max method, # ...or if the method doesn't accept a fill_value argument return asanyarray(obj).max(axis=axis, fill_value=fill_value, out=out) max.__doc__ = MaskedArray.max.__doc__ @@ -3341,7 +3341,7 @@ def ptp(obj, axis=None, out=None, fill_value=None): try: return obj.ptp(axis, out=out, fill_value=fill_value) except (AttributeError, TypeError): - # If obj doesn't have a max method, + # If obj doesn't have a max method, # ...or if the method doesn't accept a fill_value argument return asanyarray(obj).ptp(axis=axis, fill_value=fill_value, out=out) ptp.__doc__ = MaskedArray.ptp.__doc__ @@ -3770,7 +3770,7 @@ def choose (indices, choices, out=None, mode='raise'): See Also -------- choose : equivalent function - + """ def fmask (x): "Returns the filled array, or True if masked." @@ -3789,7 +3789,7 @@ def choose (indices, choices, out=None, mode='raise'): data = [fmask(x) for x in choices] # Construct the mask outputmask = np.choose(c, masks, mode=mode) - outputmask = make_mask(mask_or(outputmask, getmask(indices)), + outputmask = make_mask(mask_or(outputmask, getmask(indices)), copy=0, shrink=True) # Get the choices...... d = np.choose(c, data, mode=mode, out=out).view(MaskedArray) @@ -3995,5 +3995,3 @@ ones = _convert2ma('ones') zeros = _convert2ma('zeros') ############################################################################### - - diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index b84edf595..77b3d1923 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -401,7 +401,7 @@ def median(a, axis=None, out=None, overwrite_input=False): Notes ----- - Given a vector V with N non masked values, the median of V is the middle + Given a vector V with N non masked values, the median of V is the middle value of a sorted copy of V (Vs) - i.e. Vs[(N-1)/2], when N is odd, or {Vs[N/2 - 1] + Vs[N/2]}/2. when N is even. @@ -550,9 +550,9 @@ def mask_cols(a, axis=None): def dot(a,b, strict=False): """Return the dot product of two 2D masked arrays a and b. - Like the generic numpy equivalent, the product sum is over the last - dimension of a and the second-to-last dimension of b. If strict is True, - masked values are propagated: if a masked value appears in a row or column, + Like the generic numpy equivalent, the product sum is over the last + dimension of a and the second-to-last dimension of b. If strict is True, + masked values are propagated: if a masked value appears in a row or column, the whole row or column is considered masked. Parameters @@ -649,7 +649,7 @@ def _covhelper(x, y=None, rowvar=True, allow_masked=True): """ Private function for the computation of covariance and correlation coefficients. - + """ x = ma.array(x, ndmin=2, copy=True, dtype=float) xmask = ma.getmaskarray(x) @@ -694,9 +694,9 @@ def cov(x, y=None, rowvar=True, bias=False, allow_masked=True): Normalization is by (N-1) where N is the number of observations (unbiased estimate). If bias is True then normalization is by N. - By default, masked values are recognized as such. If x and y have the same + By default, masked values are recognized as such. If x and y have the same shape, a common mask is allocated: if x[i,j] is masked, then y[i,j] will also - be masked. + be masked. Setting `allow_masked` to False will raise an exception if values are missing in either of the input arrays. diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py index 3870fceb9..5e80695e7 100644 --- a/numpy/ma/mrecords.py +++ b/numpy/ma/mrecords.py @@ -231,7 +231,7 @@ class MaskedRecords(MaskedArray, object): if attr in ['_mask','mask','_fieldmask','fieldmask']: self.__setmask__(val) return - # Create a shortcut (so that we don't have to call getattr all the time) + # Create a shortcut (so that we don't have to call getattr all the time) _localdict = self.__dict__ # Check whether we're creating a new field newattr = attr not in _localdict @@ -262,7 +262,7 @@ class MaskedRecords(MaskedArray, object): res = fielddict[attr][:2] except (TypeError,KeyError): raise AttributeError, "record array has no attribute %s" % attr - # + # if val is masked: _fill_value = _localdict['_fill_value'] if _fill_value is not None: @@ -680,4 +680,3 @@ set to 'fi', where `i` is the number of existing fields. *newmask.dtype.fields[newfieldname]) newdata._fieldmask = newmask return newdata - diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index e24fa6f54..155d0bf73 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -199,7 +199,7 @@ class TestMaskedArray(TestCase): #self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked) def test_set_element_as_object(self): - """Tests setting elements with object""" + """Tests setting elements with object""" a = empty(1,dtype=object) x = (1,2,3,4,5) a[0] = x @@ -649,7 +649,7 @@ class TestMaskedArrayArithmetic(TestCase): npfunc = getattr(np, funcname) mafunc = getattr(numpy.ma.core, funcname) # Use the np version - nout = np.empty((4,), dtype=int) + nout = np.empty((4,), dtype=int) result = npfunc(xm,axis=0,out=nout) assert(result is nout) # Use the ma version @@ -745,7 +745,7 @@ class TestMaskedArrayArithmetic(TestCase): for funcname in funclist: npfunc = getattr(np, funcname) xmmeth = getattr(xm, funcname) - + # A ndarray as explicit input output = np.empty(4, dtype=float) output.fill(-9999) @@ -986,7 +986,7 @@ class TestFillingValues(TestCase): assert_equal(_check_fill_value(None, ndtype), control) control = np.array((0,), dtype=[('f0',float)]) assert_equal(_check_fill_value(0, ndtype), control) - # + # ndtype = np.dtype("int, (2,3)float, float") control = np.array((default_fill_value(0), default_fill_value(0.), @@ -1063,7 +1063,7 @@ class TestUfuncs(TestCase): class TestMaskedArrayInPlaceArithmetics(TestCase): "Test MaskedArray Arithmetics" - + def setUp(self): x = arange(10) y = arange(10) @@ -1643,7 +1643,7 @@ class TestMaskedArrayMethods(TestCase): # mXswapped = mX.swapaxes(0,1) assert_equal(mXswapped[-1],mX[:,-1]) - + mXXswapped = mXX.swapaxes(0,2) assert_equal(mXXswapped.shape,(2,2,3,3)) @@ -1778,7 +1778,7 @@ class TestMaskArrayMathMethod(TestCase): for funcname in ('cumsum','cumprod'): npfunc = getattr(np, funcname) xmmeth = getattr(xm, funcname) - + # A ndarray as explicit input output = np.empty((3,4), dtype=float) output.fill(-9999) @@ -1941,7 +1941,7 @@ class TestMaskedArrayFunctions(TestCase): xf = np.where(m1, 1.e+20, x) xm.set_fill_value(1.e+20) self.info = (xm, ym) - + # def test_masked_where_bool(self): x = [1,2] @@ -1988,7 +1988,7 @@ class TestMaskedArrayFunctions(TestCase): b = empty_like(a) a.round(out=b) assert_equal(b, [1., 2., 3., 5., 6.]) - + x = array([1.,2.,3.,4.,5.]) c = array([1,1,1,0,0]) x[2] = masked @@ -2004,10 +2004,10 @@ class TestMaskedArrayFunctions(TestCase): def test_round_with_output(self): "Testing round with an explicit output" - + xm = array(np.random.uniform(0,10,12)).reshape(3,4) xm[:,0] = xm[0] = xm[-1,-1] = masked - + # A ndarray as explicit input output = np.empty((3,4), dtype=float) output.fill(-9999) @@ -2062,7 +2062,7 @@ class TestMaskedArrayFunctions(TestCase): zm = masked_array(z, mask=[0,1,0,0]) xf = np.where(m1, 1.e+20, x) xm.set_fill_value(1.e+20) - + d = where(xm>2,xm,-9) assert_equal(d, [-9.,-9.,-9.,-9., -9., 4., -9., -9., 10., -9., -9., 3.]) assert_equal(d._mask, xm._mask) @@ -2114,7 +2114,7 @@ class TestMaskedArrayFunctions(TestCase): assert z[0] is masked assert z[1] is not masked assert z[2] is masked - # + # x = arange(1,6) x[-1] = masked y = arange(1,6)*10 @@ -2234,8 +2234,8 @@ class TestMaskedFields(TestCase): assert_equal_records(base._mask, np.ones(base.shape, dtype=mdtype)) # Set w/ list base.mask = [0,0,0,1,1] - assert_equal_records(base._mask, - np.array([(x,x,x) for x in [0,0,0,1,1]], + assert_equal_records(base._mask, + np.array([(x,x,x) for x in [0,0,0,1,1]], dtype=mdtype)) def test_set_record_element(self): @@ -2243,13 +2243,13 @@ class TestMaskedFields(TestCase): base = self.data['base'] (base_a, base_b, base_c) = (base['a'], base['b'], base['c']) base[0] = (pi, pi, 'pi') - + assert_equal(base_a.dtype, int) assert_equal(base_a._data, [3,2,3,4,5]) - + assert_equal(base_b.dtype, float) assert_equal(base_b._data, [pi, 2.2, 3.3, 4.4, 5.5]) - + assert_equal(base_c.dtype, '|S8') assert_equal(base_c._data, ['pi','two','three','four','five']) @@ -2257,13 +2257,13 @@ class TestMaskedFields(TestCase): base = self.data['base'] (base_a, base_b, base_c) = (base['a'], base['b'], base['c']) base[:3] = (pi, pi, 'pi') - + assert_equal(base_a.dtype, int) assert_equal(base_a._data, [3,3,3,4,5]) - + assert_equal(base_b.dtype, float) assert_equal(base_b._data, [pi, pi, pi, 4.4, 5.5]) - + assert_equal(base_c.dtype, '|S8') assert_equal(base_c._data, ['pi','pi','pi','four','five']) diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index 9fd501aaa..f6105f843 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -48,7 +48,7 @@ class TestAverage(TestCase): y = array([arange(6, dtype=float_), 2.0*arange(6)]) assert_equal(average(y, None), np.add.reduce(np.arange(6))*3./12.) assert_equal(average(y, axis=0), np.arange(6) * 3./2.) - assert_equal(average(y, axis=1), + assert_equal(average(y, axis=1), [average(x,axis=0), average(x,axis=0) * 2.0]) assert_equal(average(y, None, weights=w2), 20./6.) assert_equal(average(y, axis=0, weights=w2), @@ -395,7 +395,7 @@ class TestCov(TestCase): # 2 1D variables w/ missing values nx = x[1:-1] assert_almost_equal(np.cov(nx, nx[::-1]), cov(x, x[::-1])) - assert_almost_equal(np.cov(nx, nx[::-1], rowvar=False), + assert_almost_equal(np.cov(nx, nx[::-1], rowvar=False), cov(x, x[::-1], rowvar=False)) assert_almost_equal(np.cov(nx, nx[::-1], rowvar=False, bias=True), cov(x, x[::-1], rowvar=False, bias=True)) @@ -409,13 +409,13 @@ class TestCov(TestCase): frac = np.dot(valid, valid.T) xf = (x - x.mean(1)[:,None]).filled(0) assert_almost_equal(cov(x), np.cov(xf) * (x.shape[1]-1) / (frac - 1.)) - assert_almost_equal(cov(x, bias=True), + assert_almost_equal(cov(x, bias=True), np.cov(xf, bias=True) * x.shape[1] / frac) frac = np.dot(valid.T, valid) xf = (x - x.mean(0)).filled(0) - assert_almost_equal(cov(x, rowvar=False), + assert_almost_equal(cov(x, rowvar=False), np.cov(xf, rowvar=False) * (x.shape[0]-1)/(frac - 1.)) - assert_almost_equal(cov(x, rowvar=False, bias=True), + assert_almost_equal(cov(x, rowvar=False, bias=True), np.cov(xf, rowvar=False, bias=True) * x.shape[0]/frac) @@ -461,7 +461,7 @@ class TestCorrcoef(TestCase): # 2 1D variables w/ missing values nx = x[1:-1] assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1])) - assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False), + assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False), corrcoef(x, x[::-1], rowvar=False)) assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False, bias=True), corrcoef(x, x[::-1], rowvar=False, bias=True)) @@ -471,7 +471,7 @@ class TestCorrcoef(TestCase): x = self.data x[-1] = masked x = x.reshape(3,4) - + test = corrcoef(x) control = np.corrcoef(x) assert_almost_equal(test[:-1,:-1], control[:-1,:-1]) diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py index 901448c31..38758393c 100644 --- a/numpy/ma/tests/test_mrecords.py +++ b/numpy/ma/tests/test_mrecords.py @@ -261,7 +261,7 @@ class TestMRecords(TestCase): pass else: raise TypeError("Should have expected a readable buffer object!") - + def test_hardmask(self): "Test hardmask" @@ -275,7 +275,7 @@ class TestMRecords(TestCase): assert(not mbase._hardmask) mbase._mask = nomask # So, the mask of a field is no longer set to nomask... - assert_equal_records(mbase._mask, + assert_equal_records(mbase._mask, ma.make_mask_none(base.shape,base.dtype)) assert(ma.make_mask(mbase['b']._mask) is nomask) assert_equal(mbase['a']._mask,mbase['b']._mask) @@ -333,7 +333,7 @@ class TestMRecords(TestCase): # solo = mrecarray(1, dtype=[('f0', '<f8', (2, 2))]) solo[0] = masked - assert_equal(solo.filled(1).item(), + assert_equal(solo.filled(1).item(), np.array((1,), dtype=solo.dtype).item()) # mult = mrecarray(2, dtype= "i4, (2,3)float, float") diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py index 50b25fe04..5e881e736 100644 --- a/numpy/ma/tests/test_old_ma.py +++ b/numpy/ma/tests/test_old_ma.py @@ -167,10 +167,10 @@ class TestMa(TestCase): xmr = ravel(xm) #true because of careful selection of data - self.failUnless(eq(max(xr), maximum(xmr))) + self.failUnless(eq(max(xr), maximum(xmr))) #true because of careful selection of data - self.failUnless(eq(min(xr), minimum(xmr))) + self.failUnless(eq(min(xr), minimum(xmr))) def test_testAddSumProd (self): "Test add, sum, product." @@ -184,10 +184,10 @@ class TestMa(TestCase): self.failUnless (eq(numpy.sum(x,0), sum(x,0))) self.failUnless (eq(numpy.product(x,axis=0), product(x,axis=0))) self.failUnless (eq(numpy.product(x,0), product(x,0))) - self.failUnless (eq(numpy.product(filled(xm,1),axis=0), + self.failUnless (eq(numpy.product(filled(xm,1),axis=0), product(xm,axis=0))) if len(s) > 1: - self.failUnless (eq(numpy.concatenate((x,y),1), + self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1))) self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1))) self.failUnless (eq(numpy.sum(x,1), sum(x,1))) @@ -361,7 +361,7 @@ class TestMa(TestCase): assert z[1] is not masked assert z[2] is masked assert eq(masked_where(greater(x, 2), x), masked_greater(x,2)) - assert eq(masked_where(greater_equal(x, 2), x), + assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2)) assert eq(masked_where(less(x, 2), x), masked_less(x,2)) assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2)) @@ -370,13 +370,13 @@ class TestMa(TestCase): assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2)) assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4]) assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199]) - assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, + assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0]) assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1]) - assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, + assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0]) - assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, + assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1]) assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5]) atest = ones((10,10,10), dtype=float32) @@ -537,15 +537,15 @@ class TestMa(TestCase): self.failUnless(allclose(average(x, axis=0), 2.5)) self.failUnless(allclose(average(x, axis=0, weights=w1), 2.5)) y=array([arange(6), 2.0*arange(6)]) - self.failUnless(allclose(average(y, None), + self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.)) self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.)) - self.failUnless(allclose(average(y, axis=1), + self.failUnless(allclose(average(y, axis=1), [average(x,axis=0), average(x,axis=0) * 2.0])) self.failUnless(allclose(average(y, None, weights=w2), 20./6.)) - self.failUnless(allclose(average(y, axis=0, weights=w2), + self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.])) - self.failUnless(allclose(average(y, axis=1), + self.failUnless(allclose(average(y, axis=1), [average(x,axis=0), average(x,axis=0) * 2.0])) m1 = zeros(6) m2 = [0,0,1,1,0,0] @@ -561,7 +561,7 @@ class TestMa(TestCase): self.failUnless(allclose(average(z, None), 20./6.)) self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5])) self.failUnless(allclose(average(z, axis=1), [2.5, 5.0])) - self.failUnless(allclose( average(z,axis=0, weights=w2), + self.failUnless(allclose( average(z,axis=0, weights=w2), [0.,1., 99., 99., 4.0, 10.0])) a = arange(6) @@ -674,9 +674,9 @@ class TestUfuncs(TestCase): mf = getattr(numpy.ma, f) args = self.d[:uf.nin] olderr = numpy.geterr() - f_invalid_ignore = ['sqrt', 'arctanh', 'arcsin', 'arccos', + f_invalid_ignore = ['sqrt', 'arctanh', 'arcsin', 'arccos', 'arccosh', 'arctanh', 'log', 'log10','divide', - 'true_divide', 'floor_divide', 'remainder', + 'true_divide', 'floor_divide', 'remainder', 'fmod'] if f in f_invalid_ignore: numpy.seterr(invalid='ignore') diff --git a/numpy/ma/testutils.py b/numpy/ma/testutils.py index 33030489c..8de590be5 100644 --- a/numpy/ma/testutils.py +++ b/numpy/ma/testutils.py @@ -147,9 +147,9 @@ def assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True): The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal) """ if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray): - return assert_array_almost_equal(actual, desired, decimal=decimal, + return assert_array_almost_equal(actual, desired, decimal=decimal, err_msg=err_msg, verbose=verbose) - msg = build_err_msg([actual, desired], + msg = build_err_msg([actual, desired], err_msg=err_msg, verbose=verbose) assert round(abs(desired - actual),decimal) == 0, msg @@ -170,13 +170,13 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', y = masked_array(yf, copy=False, mask=m) if ((x is masked) and not (y is masked)) or \ ((y is masked) and not (x is masked)): - msg = build_err_msg([x, y], err_msg=err_msg, verbose=verbose, + msg = build_err_msg([x, y], err_msg=err_msg, verbose=verbose, header=header, names=('x', 'y')) raise ValueError(msg) # OK, now run the basic tests on filled versions - return utils.assert_array_compare(comparison, - x.filled(fill_value), y.filled(fill_value), - err_msg=err_msg, + return utils.assert_array_compare(comparison, + x.filled(fill_value), y.filled(fill_value), + err_msg=err_msg, verbose=verbose, header=header) diff --git a/numpy/setupscons.py b/numpy/setupscons.py index 36324cc10..ef1ef8061 100644 --- a/numpy/setupscons.py +++ b/numpy/setupscons.py @@ -6,7 +6,7 @@ def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import scons_generate_config_py pkgname = 'numpy' - config = Configuration(pkgname, parent_package, top_path, + config = Configuration(pkgname, parent_package, top_path, setup_name = 'setupscons.py') config.add_subpackage('distutils') config.add_subpackage('testing') @@ -27,7 +27,7 @@ def configuration(parent_package='', top_path=None): if kw['scons_cmd'].inplace: target = pjoin(kw['pkg_name'], '__config__.py') else: - target = pjoin(kw['scons_cmd'].build_lib, kw['pkg_name'], + target = pjoin(kw['scons_cmd'].build_lib, kw['pkg_name'], '__config__.py') scons_generate_config_py(target) config.add_sconscript(None, post_hook = add_config) diff --git a/numpy/testing/__init__.py b/numpy/testing/__init__.py index 06e49cf2a..53941fd76 100644 --- a/numpy/testing/__init__.py +++ b/numpy/testing/__init__.py @@ -10,7 +10,7 @@ from unittest import TestCase import decorators as dec from utils import * -from parametric import ParametricTestCase +from parametric import ParametricTestCase from numpytest import * from nosetester import NoseTester as Tester from nosetester import run_module_suite diff --git a/numpy/testing/decorators.py b/numpy/testing/decorators.py index dd9783e2f..77871d339 100644 --- a/numpy/testing/decorators.py +++ b/numpy/testing/decorators.py @@ -72,8 +72,8 @@ def skipif(skip_condition, msg=None): if msg is None: msg = 'Test skipped due to test condition' def skip_decorator(f): - # Local import to avoid a hard nose dependency and only incur the - # import time overhead at actual test-time. + # Local import to avoid a hard nose dependency and only incur the + # import time overhead at actual test-time. import nose def skipper(*args, **kwargs): if skip_condition: @@ -86,8 +86,8 @@ def skipif(skip_condition, msg=None): def skipknownfailure(f): ''' Decorator to raise SkipTest for test known to fail ''' - # Local import to avoid a hard nose dependency and only incur the - # import time overhead at actual test-time. + # Local import to avoid a hard nose dependency and only incur the + # import time overhead at actual test-time. import nose def skipper(*args, **kwargs): raise nose.SkipTest, 'This test is known to fail' diff --git a/numpy/testing/noseclasses.py b/numpy/testing/noseclasses.py index c2fb85e0b..68b9dff8f 100644 --- a/numpy/testing/noseclasses.py +++ b/numpy/testing/noseclasses.py @@ -134,12 +134,12 @@ class numpyDocTestCase(npd.DocTestCase): return name -# second-chance checker; if the default comparison doesn't +# second-chance checker; if the default comparison doesn't # pass, then see if the expected output string contains flags that # tell us to ignore the output class numpyOutputChecker(doctest.OutputChecker): def check_output(self, want, got, optionflags): - ret = doctest.OutputChecker.check_output(self, want, got, + ret = doctest.OutputChecker.check_output(self, want, got, optionflags) if not ret: if "#random" in want: @@ -148,7 +148,7 @@ class numpyOutputChecker(doctest.OutputChecker): return ret -# Subclass nose.plugins.doctests.DocTestCase to work around a bug in +# Subclass nose.plugins.doctests.DocTestCase to work around a bug in # its constructor that blocks non-default arguments from being passed # down into doctest.DocTestCase class numpyDocTestCase(npd.DocTestCase): @@ -156,13 +156,13 @@ class numpyDocTestCase(npd.DocTestCase): checker=None, obj=None, result_var='_'): self._result_var = result_var self._nose_obj = obj - doctest.DocTestCase.__init__(self, test, + doctest.DocTestCase.__init__(self, test, optionflags=optionflags, - setUp=setUp, tearDown=tearDown, + setUp=setUp, tearDown=tearDown, checker=checker) -print_state = numpy.get_printoptions() +print_state = numpy.get_printoptions() class numpyDoctest(npd.Doctest): name = 'numpydoctest' # call nosetests with --with-numpydoctest @@ -188,7 +188,7 @@ class numpyDoctest(npd.Doctest): try: tests = self.finder.find(module) except AttributeError: - # nose allows module.__test__ = False; doctest does not and + # nose allows module.__test__ = False; doctest does not and # throws AttributeError return if not tests: @@ -205,31 +205,31 @@ class numpyDoctest(npd.Doctest): # Each doctest should execute in an environment equivalent to # starting Python and executing "import numpy as np", and, - # for SciPy packages, an additional import of the local + # for SciPy packages, an additional import of the local # package (so that scipy.linalg.basic.py's doctests have an # implicit "from scipy import linalg" as well. # # Note: __file__ allows the doctest in NoseTester to run # without producing an error test.globs = {'__builtins__':__builtins__, - '__file__':'__main__', - '__name__':'__main__', + '__file__':'__main__', + '__name__':'__main__', 'np':numpy} - + # add appropriate scipy import for SciPy tests if 'scipy' in pkg_name: p = pkg_name.split('.') p1 = '.'.join(p[:-1]) p2 = p[-1] test.globs[p2] = __import__(pkg_name, test.globs, {}, [p2]) - + print 'additional import for %s: from %s import %s' % (test.filename, p1, p2) print ' (%s): %r' % (pkg_name, test.globs[p2]) # always use whitespace and ellipsis options optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS - yield numpyDocTestCase(test, + yield numpyDocTestCase(test, optionflags=optionflags, checker=numpyOutputChecker()) diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py index 3465fd3ef..ed46681e1 100644 --- a/numpy/testing/nosetester.py +++ b/numpy/testing/nosetester.py @@ -81,7 +81,7 @@ def _docmethod(meth, testtype): extra_argv : list List with any extra args to pass to nosetests''' \ % {'testtype': testtype} - + meth.__doc__ = meth.__doc__ % {'test_header':test_header} @@ -123,7 +123,7 @@ class NoseTester(object): package = os.path.dirname(package.__file__) self.package_path = package - # find the package name under test; this name is used to limit coverage + # find the package name under test; this name is used to limit coverage # reporting (if enabled) self.package_name = get_package_name(package) @@ -144,8 +144,8 @@ class NoseTester(object): argv += extra_argv return argv - - def test(self, label='fast', verbose=1, extra_argv=None, doctests=False, + + def test(self, label='fast', verbose=1, extra_argv=None, doctests=False, coverage=False, **kwargs): ''' Run tests for module using nose @@ -154,7 +154,7 @@ class NoseTester(object): If True, run doctests in module, default False coverage : boolean If True, report coverage of NumPy code, default False - (Requires the coverage module: + (Requires the coverage module: http://nedbatchelder.com/code/modules/coverage.html) ''' @@ -165,15 +165,15 @@ class NoseTester(object): ua = ', '.join(unexpected_args) raise TypeError("test() got unexpected arguments: %s" % ua) - # issue a deprecation warning if any of the pre-1.2 arguments to + # issue a deprecation warning if any of the pre-1.2 arguments to # test are given if old_args.intersection(kwargs.keys()): warnings.warn("This method's signature will change in the next " \ "release; the level, verbosity, all, sys_argv, " \ "and testcase_pattern keyword arguments will be " \ - "removed. Please update your code.", + "removed. Please update your code.", DeprecationWarning, stacklevel=2) - + # Use old arguments if given (where it makes sense) # For the moment, level and sys_argv are ignored @@ -191,7 +191,7 @@ class NoseTester(object): label = '' doctests = True - # if doctests is in the extra args, remove it and set the doctest + # if doctests is in the extra args, remove it and set the doctest # flag so the NumPy doctester is used instead if extra_argv and '--with-doctest' in extra_argv: extra_argv.remove('--with-doctest') @@ -222,23 +222,23 @@ class NoseTester(object): print "NumPy version %s" % numpy.__version__ npdir = os.path.dirname(numpy.__file__) print "NumPy is installed in %s" % npdir - + if 'scipy' in self.package_name: import scipy print "SciPy version %s" % scipy.__version__ spdir = os.path.dirname(scipy.__file__) print "SciPy is installed in %s" % spdir - + pyversion = sys.version.replace('\n','') print "Python version %s" % pyversion print "nose version %d.%d.%d" % nose.__versioninfo__ - # Because nose currently discards the test result object, but we need - # to return it to the user, override TestProgram.runTests to retain + # Because nose currently discards the test result object, but we need + # to return it to the user, override TestProgram.runTests to retain # the result class NumpyTestProgram(nose.core.TestProgram): def runTests(self): - """Run Tests. Returns true on success, false on failure, and + """Run Tests. Returns true on success, false on failure, and sets self.success to the same value. """ if self.testRunner is None: @@ -257,7 +257,7 @@ class NoseTester(object): doctest.master = None # construct list of plugins, omitting the existing doctest plugin - import nose.plugins.builtin + import nose.plugins.builtin from noseclasses import numpyDoctest plugins = [numpyDoctest()] for p in nose.plugins.builtin.plugins: @@ -307,10 +307,9 @@ def check_whitespace_enabled(): ''' # whitespace after the 3 >>> 1+2 - 3 + 3 # whitespace before the 7 >>> 3+4 7 ''' - diff --git a/numpy/testing/numpytest.py b/numpy/testing/numpytest.py index 06229630a..c08215383 100644 --- a/numpy/testing/numpytest.py +++ b/numpy/testing/numpytest.py @@ -623,7 +623,7 @@ class NumpyTest: """ Run Numpy module test suite with level and verbosity taken from sys.argv. Requires optparse module. """ - + # delayed import of shlex to reduce startup time import shlex diff --git a/numpy/testing/parametric.py b/numpy/testing/parametric.py index 3727d3ef2..7ff68f260 100644 --- a/numpy/testing/parametric.py +++ b/numpy/testing/parametric.py @@ -189,7 +189,7 @@ class _ParametricTestCase(unittest.TestCase): else: unittest.TestCase.run(self,result) -# The underscore was added to the class name to keep nose from trying +# The underscore was added to the class name to keep nose from trying # to run the test class (nose ignores class names that begin with an # underscore by default). ParametricTestCase = _ParametricTestCase diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index af22e68ac..f28a6dd68 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -10,7 +10,7 @@ from nosetester import import_nose __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', 'assert_string_equal', - 'assert_array_almost_equal', 'assert_raises', 'build_err_msg', + 'assert_array_almost_equal', 'assert_raises', 'build_err_msg', 'decorate_methods', 'jiffies', 'memusage', 'print_assert_equal', 'raises', 'rand', 'rundocs', 'runstring', 'verbose'] |