From 2529e10c6e63a6bfcf09f32cc592e2c64516803c Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Fri, 19 Apr 2013 04:42:30 +0000 Subject: [PATCH] PEP8: Fix E203 whitespace before ',' --- scipy/constants/codata.py | 6 +-- scipy/fftpack/tests/test_basic.py | 8 ++-- scipy/integrate/tests/test_quadrature.py | 12 ++--- scipy/interpolate/fitpack.py | 2 +- scipy/interpolate/interpolate_wrapper.py | 2 +- scipy/io/arff/arffread.py | 6 +-- scipy/io/matlab/benchmarks/bench_structarr.py | 2 +- scipy/io/matlab/mio5.py | 2 +- scipy/lib/lapack/tests/common.py | 22 +++++----- scipy/linalg/_decomp_qz.py | 2 +- scipy/linalg/blas.py | 6 +-- scipy/linalg/misc.py | 2 +- scipy/linalg/tests/test_decomp.py | 16 +++---- scipy/linalg/tests/test_matfuncs.py | 8 ++-- scipy/ndimage/filters.py | 2 +- scipy/ndimage/tests/test_ndimage.py | 8 ++-- scipy/odr/tests/test_odr.py | 4 +- scipy/optimize/_tstutils.py | 24 +++++----- scipy/optimize/anneal.py | 30 ++++++------- scipy/optimize/benchmarks/bench_zeros.py | 6 +-- scipy/optimize/slsqp.py | 44 +++++++++---------- scipy/optimize/tests/test_anneal.py | 10 ++--- scipy/optimize/tests/test_nonlin.py | 4 +- scipy/optimize/tests/test_optimize.py | 6 +-- scipy/optimize/tests/test_tnc.py | 2 +- scipy/optimize/tests/test_zeros.py | 4 +- scipy/optimize/tnc.py | 32 +++++++------- scipy/optimize/zeros.py | 10 ++--- scipy/signal/tests/test_signaltools.py | 18 ++++---- scipy/sparse/linalg/dsolve/linsolve.py | 4 +- .../dsolve/umfpack/tests/try_umfpack.py | 2 +- scipy/sparse/linalg/dsolve/umfpack/umfpack.py | 42 +++++++++--------- .../linalg/eigen/arpack/tests/test_arpack.py | 10 ++--- scipy/sparse/linalg/eigen/lobpcg/lobpcg.py | 2 +- scipy/sparse/linalg/isolve/minres.py | 30 ++++++------- .../linalg/isolve/tests/test_iterative.py | 2 +- scipy/sparse/tests/test_base.py | 6 +-- scipy/special/tests/test_basic.py | 16 +++---- scipy/special/tests/test_logit.py | 8 ++-- scipy/stats/distributions.py | 4 +- scipy/stats/stats.py | 2 +- scipy/stats/tests/test_distributions.py | 14 +++--- scipy/stats/tests/test_mstats_basic.py | 12 ++--- scipy/stats/tests/test_stats.py | 34 +++++++------- scipy/weave/accelerate_tools.py | 6 +-- scipy/weave/bytecodecompiler.py | 2 +- tox.ini | 2 +- 47 files changed, 249 insertions(+), 249 deletions(-) diff --git a/scipy/constants/codata.py b/scipy/constants/codata.py index 43a76d958bd1..621f51e9a44a 100644 --- a/scipy/constants/codata.py +++ b/scipy/constants/codata.py @@ -856,7 +856,7 @@ def _check_obsolete(key): key, _current_codata), ConstantWarning) -def value(key) : +def value(key): """ Value in physical_constants indexed by key @@ -886,7 +886,7 @@ def value(key) : return physical_constants[key][0] -def unit(key) : +def unit(key): """ Unit in physical_constants indexed by key @@ -916,7 +916,7 @@ def unit(key) : return physical_constants[key][1] -def precision(key) : +def precision(key): """ Relative precision in physical_constants indexed by key diff --git a/scipy/fftpack/tests/test_basic.py b/scipy/fftpack/tests/test_basic.py index 49c01f408d17..c5b71c11b47b 100644 --- a/scipy/fftpack/tests/test_basic.py +++ b/scipy/fftpack/tests/test_basic.py @@ -505,12 +505,12 @@ def test_axes_argument(self): assert_array_almost_equal(swapaxes(y,-1,-3),fftn(ijk_space)) y = fftn(x,axes=(2,0,1)) # ikj_space assert_array_almost_equal(swapaxes(swapaxes(y,-1,-3), - -1,-2) - ,fftn(ikj_space)) + -1,-2), + fftn(ikj_space)) y = fftn(x,axes=(1,2,0)) # jik_space assert_array_almost_equal(swapaxes(swapaxes(y,-1,-3), - -3,-2) - ,fftn(jik_space)) + -3,-2), + fftn(jik_space)) y = fftn(x,axes=(1,0,2)) # jki_space assert_array_almost_equal(swapaxes(y,-2,-3),fftn(jki_space)) y = fftn(x,axes=(0,2,1)) # kij_space diff --git a/scipy/integrate/tests/test_quadrature.py b/scipy/integrate/tests/test_quadrature.py index e7c052c9a5a5..e45efd319731 100644 --- a/scipy/integrate/tests/test_quadrature.py +++ b/scipy/integrate/tests/test_quadrature.py @@ -108,12 +108,12 @@ def test_nd(self): x = np.arange(3 * 2 * 4).reshape(3, 2, 4) y = x y_int = cumtrapz(y, x, initial=0) - y_expected = np.array([[[0. , 0.5, 2. , 4.5], - [0. , 4.5, 10. , 16.5]], - [[0. , 8.5, 18. , 28.5], - [0. , 12.5, 26. , 40.5]], - [[0. , 16.5, 34. , 52.5], - [0. , 20.5, 42. , 64.5]]]) + y_expected = np.array([[[0., 0.5, 2., 4.5], + [0., 4.5, 10., 16.5]], + [[0., 8.5, 18., 28.5], + [0., 12.5, 26., 40.5]], + [[0., 16.5, 34., 52.5], + [0., 20.5, 42., 64.5]]]) assert_allclose(y_int, y_expected) diff --git a/scipy/interpolate/fitpack.py b/scipy/interpolate/fitpack.py index 62a5c1ff3f1a..bd8c267b9b84 100644 --- a/scipy/interpolate/fitpack.py +++ b/scipy/interpolate/fitpack.py @@ -558,7 +558,7 @@ def splev(x, tck, der=0, ext=0): except: parametric = False if parametric: - return list(map(lambda c, x=x, t=t, k=k, der=der : splev(x, [t,c,k], der, ext), c)) + return list(map(lambda c, x=x, t=t, k=k, der=der: splev(x, [t,c,k], der, ext), c)) else: if not (0 <= der <= k): raise ValueError("0<=der=%d<=k=%d must hold" % (der,k)) diff --git a/scipy/interpolate/interpolate_wrapper.py b/scipy/interpolate/interpolate_wrapper.py index ed3e51a338ee..15ecf27aa748 100644 --- a/scipy/interpolate/interpolate_wrapper.py +++ b/scipy/interpolate/interpolate_wrapper.py @@ -30,7 +30,7 @@ def nearest(x, y, new_x): Rounds each `new_x` to nearest `x` and returns the corresponding `y`. """ - shifted_x = np.concatenate((np.array([x[0]-1]) , x[0:-1])) + shifted_x = np.concatenate((np.array([x[0]-1]), x[0:-1])) midpoints_of_x = atleast_1d_and_contiguous(.5*(x + shifted_x)) new_x = atleast_1d_and_contiguous(new_x) diff --git a/scipy/io/arff/arffread.py b/scipy/io/arff/arffread.py index dad8185e83a0..b10bd85497f8 100644 --- a/scipy/io/arff/arffread.py +++ b/scipy/io/arff/arffread.py @@ -173,7 +173,7 @@ def go_data(ofile): """Skip header. the first next() call of the returned iterator will be the @data line""" - return itertools.dropwhile(lambda x : not r_datameta.match(x), ofile) + return itertools.dropwhile(lambda x: not r_datameta.match(x), ofile) #---------------- @@ -542,8 +542,8 @@ def _loadarff(ofile): # This can be used once we want to support integer as integer values and # not as numeric anymore (using masked arrays ?). - acls2dtype = {'real' : np.float, 'integer' : np.float, 'numeric' : np.float} - acls2conv = {'real' : safe_float, 'integer' : safe_float, 'numeric' : safe_float} + acls2dtype = {'real': np.float, 'integer': np.float, 'numeric': np.float} + acls2conv = {'real': safe_float, 'integer': safe_float, 'numeric': safe_float} descr = [] convertors = [] if not hasstr: diff --git a/scipy/io/matlab/benchmarks/bench_structarr.py b/scipy/io/matlab/benchmarks/bench_structarr.py index 7837f69e26eb..5cd55460459d 100644 --- a/scipy/io/matlab/benchmarks/bench_structarr.py +++ b/scipy/io/matlab/benchmarks/bench_structarr.py @@ -40,5 +40,5 @@ def bench_run(): n_structs)) -if __name__ == '__main__' : +if __name__ == '__main__': bench_run() diff --git a/scipy/io/matlab/mio5.py b/scipy/io/matlab/mio5.py index c1db25713a8b..13fc51216834 100644 --- a/scipy/io/matlab/mio5.py +++ b/scipy/io/matlab/mio5.py @@ -484,7 +484,7 @@ def to_writeable(source): dtype.append((field,object)) values.append(value) if dtype: - return np.array([tuple(values)] ,dtype) + return np.array([tuple(values)],dtype) else: return None # Next try and convert to an array diff --git a/scipy/lib/lapack/tests/common.py b/scipy/lib/lapack/tests/common.py index 3255895aba0c..a60ffdbca635 100644 --- a/scipy/lib/lapack/tests/common.py +++ b/scipy/lib/lapack/tests/common.py @@ -4,19 +4,19 @@ from scipy.lib.lapack import flapack, clapack -FUNCS_TP = {'ssygv' : np.float32, +FUNCS_TP = {'ssygv': np.float32, 'dsygv': np.float, - 'ssygvd' : np.float32, - 'dsygvd' : np.float, - 'ssyev' : np.float32, + 'ssygvd': np.float32, + 'dsygvd': np.float, + 'ssyev': np.float32, 'dsyev': np.float, - 'ssyevr' : np.float32, - 'dsyevr' : np.float, - 'ssyevr' : np.float32, - 'dsyevr' : np.float, - 'sgehrd' : np.float32, - 'dgehrd' : np.float, - 'sgebal' : np.float32, + 'ssyevr': np.float32, + 'dsyevr': np.float, + 'ssyevr': np.float32, + 'dsyevr': np.float, + 'sgehrd': np.float32, + 'dgehrd': np.float, + 'sgebal': np.float32, 'dgebal': np.float} # Test FLAPACK if not empty diff --git a/scipy/linalg/_decomp_qz.py b/scipy/linalg/_decomp_qz.py index f88ea2f34b83..19988cc27a80 100644 --- a/scipy/linalg/_decomp_qz.py +++ b/scipy/linalg/_decomp_qz.py @@ -208,7 +208,7 @@ def qz(A, B, output='real', lwork=None, sort=None, overwrite_a=False, if sort is None: sort_t = 0 - sfunction = lambda x : None + sfunction = lambda x: None else: sort_t = 1 sfunction = _select_function(sort, typa) diff --git a/scipy/linalg/blas.py b/scipy/linalg/blas.py index 7fdd4a300b26..a3f26146ba07 100644 --- a/scipy/linalg/blas.py +++ b/scipy/linalg/blas.py @@ -130,9 +130,9 @@ _type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z', 'G':'z'} # some convenience alias for complex functions -_blas_alias = {'cnrm2' : 'scnrm2', 'znrm2' : 'dznrm2', - 'cdot' : 'cdotc', 'zdot' : 'zdotc', - 'cger' : 'cgerc', 'zger' : 'zgerc', +_blas_alias = {'cnrm2': 'scnrm2', 'znrm2': 'dznrm2', + 'cdot': 'cdotc', 'zdot': 'zdotc', + 'cger': 'cgerc', 'zger': 'zgerc', 'sdotc': 'sdot', 'sdotu': 'sdot', 'ddotc': 'ddot', 'ddotu': 'ddot'} diff --git a/scipy/linalg/misc.py b/scipy/linalg/misc.py index ab3630f43347..aebac1cf4d13 100644 --- a/scipy/linalg/misc.py +++ b/scipy/linalg/misc.py @@ -6,7 +6,7 @@ __all__ = ['LinAlgError', 'norm'] -_nrm2_prefix = {'f' : 's', 'F': 'sc', 'D': 'dz'} +_nrm2_prefix = {'f': 's', 'F': 'sc', 'D': 'dz'} def norm(a, ord=None): diff --git a/scipy/linalg/tests/test_decomp.py b/scipy/linalg/tests/test_decomp.py index 93f8cc4b56e0..66e937788ee8 100644 --- a/scipy/linalg/tests/test_decomp.py +++ b/scipy/linalg/tests/test_decomp.py @@ -1817,7 +1817,7 @@ def test_qz_double_sort(self): [1.0, 2.0, -4.0, 1.0], [1.2, 3.0, -4.0, 4.0]]) - sort = lambda ar,ai,beta : ai == 0 + sort = lambda ar,ai,beta: ai == 0 assert_raises(ValueError, qz, A, B, sort=sort) if False: @@ -1831,16 +1831,16 @@ def test_qz_double_sort(self): # dependent assert_array_almost_equal(np.abs(AA), np.abs(np.array( [[35.7864, -80.9061, -12.0629, -9.498], - [0. , 2.7638, -2.3505, 7.3256], - [0. , 0. , 0.6258, -0.0398], - [0. , 0. , 0. , -12.8217]])), 4) + [0., 2.7638, -2.3505, 7.3256], + [0., 0., 0.6258, -0.0398], + [0., 0., 0., -12.8217]])), 4) assert_array_almost_equal(np.abs(BB), np.abs(np.array( [[4.5324, -8.7878, 3.2357, -3.5526], - [0. , 1.4314, -2.1894, 0.9709], - [0. , 0. , 1.3126, -0.3468], - [0. , 0. , 0. , 0.559]])), 4) + [0., 1.4314, -2.1894, 0.9709], + [0., 0., 1.3126, -0.3468], + [0., 0., 0., 0.559]])), 4) assert_array_almost_equal(np.abs(Q), np.abs(np.array( - [[-0.4193, -0.605 , -0.1894, -0.6498], + [[-0.4193, -0.605, -0.1894, -0.6498], [-0.5495, 0.6987, 0.2654, -0.3734], [-0.4973, -0.3682, 0.6194, 0.4832], [-0.5243, 0.1008, -0.7142, 0.4526]])), 4) diff --git a/scipy/linalg/tests/test_matfuncs.py b/scipy/linalg/tests/test_matfuncs.py index c40c66e818c5..fadeb8f87754 100644 --- a/scipy/linalg/tests/test_matfuncs.py +++ b/scipy/linalg/tests/test_matfuncs.py @@ -20,13 +20,13 @@ class TestSignM(TestCase): def test_nils(self): a = array([[29.2, -24.2, 69.5, 49.8, 7.], - [-9.2, 5.2, -18. , -16.8, -2.], - [-10. , 6. , -20. , -18. , -2.], + [-9.2, 5.2, -18., -16.8, -2.], + [-10., 6., -20., -18., -2.], [-9.6, 9.6, -25.5, -15.4, -2.], - [9.8, -4.8, 18. , 18.2, 2.]]) + [9.8, -4.8, 18., 18.2, 2.]]) cr = array([[11.94933333,-2.24533333,15.31733333,21.65333333,-2.24533333], [-3.84266667,0.49866667,-4.59066667,-7.18666667,0.49866667], - [-4.08,0.56,-4.92,-7.6 ,0.56], + [-4.08,0.56,-4.92,-7.6,0.56], [-4.03466667,1.04266667,-5.59866667,-7.02666667,1.04266667], [4.15733333,-0.50133333,4.90933333,7.81333333,-0.50133333]]) r = signm(a) diff --git a/scipy/ndimage/filters.py b/scipy/ndimage/filters.py index 135335410a3a..6f2f5ecb330e 100644 --- a/scipy/ndimage/filters.py +++ b/scipy/ndimage/filters.py @@ -220,7 +220,7 @@ def gaussian_filter1d(input, sigma, axis=-1, order=0, output=None, for ii in range(2 * lw + 1): weights[ii] /= sum # implement first, second and third order derivatives: - if order == 1 : # first derivative + if order == 1: # first derivative weights[lw] = 0.0 for ii in range(1, lw + 1): x = float(ii) diff --git a/scipy/ndimage/tests/test_ndimage.py b/scipy/ndimage/tests/test_ndimage.py index 1a3d69f832c4..a5c2e83b942d 100644 --- a/scipy/ndimage/tests/test_ndimage.py +++ b/scipy/ndimage/tests/test_ndimage.py @@ -1312,8 +1312,8 @@ def shift(x): data = numpy.array([1,2,3,4.]) expected = {'constant': [1.5,2.5,3.5,-1,-1,-1,-1], 'wrap': [1.5,2.5,3.5,1.5,2.5,3.5,1.5], - 'mirror' : [1.5,2.5,3.5,3.5,2.5,1.5,1.5], - 'nearest' : [1.5,2.5,3.5,4,4,4,4]} + 'mirror': [1.5,2.5,3.5,3.5,2.5,1.5,1.5], + 'nearest': [1.5,2.5,3.5,4,4,4,4]} for mode in expected: assert_array_equal(expected[mode], @@ -1330,8 +1330,8 @@ def shift(x): data = numpy.array([1,2,3,4]) expected = {'constant': [-1,1,2,3], 'wrap': [3,1,2,3], - 'mirror' : [2,1,2,3], - 'nearest' : [1,1,2,3]} + 'mirror': [2,1,2,3], + 'nearest': [1,1,2,3]} for mode in expected: assert_array_equal(expected[mode], diff --git a/scipy/odr/tests/test_odr.py b/scipy/odr/tests/test_odr.py index eba7e1cbb226..e7977c01f560 100644 --- a/scipy/odr/tests/test_odr.py +++ b/scipy/odr/tests/test_odr.py @@ -51,7 +51,7 @@ def test_explicit(self): ) assert_array_almost_equal( out.sd_beta, - np.array([1.0349270280543437, 1.583997785262061 , 0.0063321988657267]), + np.array([1.0349270280543437, 1.583997785262061, 0.0063321988657267]), ) assert_array_almost_equal( out.cov_beta, @@ -203,7 +203,7 @@ def test_multi(self): -0.0563083340093696, 0.1269490939468611], [-0.0058700836512467, -0.0051181304940204, -0.0563083340093696, 0.0066939246261263, -0.0140184391377962], - [0.011281212888768 , 0.0130726943624117, 0.1269490939468611, + [0.011281212888768, 0.0130726943624117, 0.1269490939468611, -0.0140184391377962, 0.0316733013820852]]), ) diff --git a/scipy/optimize/_tstutils.py b/scipy/optimize/_tstutils.py index adfb3942a8cf..004435565264 100644 --- a/scipy/optimize/_tstutils.py +++ b/scipy/optimize/_tstutils.py @@ -6,38 +6,38 @@ from scipy.optimize import zeros as cc -def f1(x) : +def f1(x): return x*(x-1.) -def f2(x) : +def f2(x): return x**2 - 1 -def f3(x) : +def f3(x): return x*(x-1.)*(x-2.)*(x-3.) -def f4(x) : - if x > 1 : +def f4(x): + if x > 1: return 1.0 + .1*x - if x < 1 : + if x < 1: return -1.0 + .1*x return 0 -def f5(x) : - if x != 1 : +def f5(x): + if x != 1: return 1.0/(1. - x) return 0 -def f6(x) : - if x > 1 : +def f6(x): + if x > 1: return random() - elif x < 1 : + elif x < 1: return -random() - else : + else: return 0 description = """ diff --git a/scipy/optimize/anneal.py b/scipy/optimize/anneal.py index eafe0ceef114..e9aaad9d658f 100644 --- a/scipy/optimize/anneal.py +++ b/scipy/optimize/anneal.py @@ -428,22 +428,22 @@ def anneal(func, x0, args=(), schedule='fast', full_output=0, """ - opts = {'schedule' : schedule, - 'T0' : T0, - 'Tf' : Tf, - 'maxfev' : maxeval, - 'maxaccept' : maxaccept, - 'maxiter' : maxiter, - 'boltzmann' : boltzmann, + opts = {'schedule': schedule, + 'T0': T0, + 'Tf': Tf, + 'maxfev': maxeval, + 'maxaccept': maxaccept, + 'maxiter': maxiter, + 'boltzmann': boltzmann, 'learn_rate': learn_rate, - 'ftol' : feps, - 'quench' : quench, - 'm' : m, - 'n' : n, - 'lower' : lower, - 'upper' : upper, - 'dwell' : dwell, - 'disp' : disp} + 'ftol': feps, + 'quench': quench, + 'm': m, + 'n': n, + 'lower': lower, + 'upper': upper, + 'dwell': dwell, + 'disp': disp} res = _minimize_anneal(func, x0, args, **opts) diff --git a/scipy/optimize/benchmarks/bench_zeros.py b/scipy/optimize/benchmarks/bench_zeros.py index 08f0c58f0b80..9277f585cabf 100644 --- a/scipy/optimize/benchmarks/bench_zeros.py +++ b/scipy/optimize/benchmarks/bench_zeros.py @@ -21,10 +21,10 @@ def bench_run(self): print('TESTING SPEED\n') print('times in seconds for %d iterations \n' % repeat) - for i in range(len(functions)) : + for i in range(len(functions)): print('function %s\n' % fstrings[i]) func = functions[i] - for j in range(len(methods)) : + for j in range(len(methods)): meth = methods[j] try: t = measure("meth(func,a,b)",repeat) @@ -34,5 +34,5 @@ def bench_run(self): print('%s : %5.3f' % (mstrings[j],t)) print('\n\n') -if __name__ == '__main__' : +if __name__ == '__main__': run_module_suite() diff --git a/scipy/optimize/slsqp.py b/scipy/optimize/slsqp.py index 9a75cf71b743..e319c6d9b1e5 100644 --- a/scipy/optimize/slsqp.py +++ b/scipy/optimize/slsqp.py @@ -64,7 +64,7 @@ def approx_jacobian(x,func,epsilon,*args): return jac.transpose() -def fmin_slsqp(func, x0 , eqcons=[], f_eqcons=None, ieqcons=[], f_ieqcons=None, +def fmin_slsqp(func, x0, eqcons=[], f_eqcons=None, ieqcons=[], f_ieqcons=None, bounds=[], fprime=None, fprime_eqcons=None, fprime_ieqcons=None, args=(), iter = 100, acc = 1.0E-6, iprint = 1, disp = None, full_output = 0, epsilon = _epsilon): @@ -174,17 +174,17 @@ def fmin_slsqp(func, x0 , eqcons=[], f_eqcons=None, ieqcons=[], f_ieqcons=None, if disp is not None: iprint = disp opts = {'maxiter': iter, - 'ftol' : acc, - 'iprint' : iprint, - 'disp' : iprint != 0, - 'eps' : epsilon} + 'ftol': acc, + 'iprint': iprint, + 'disp': iprint != 0, + 'eps': epsilon} # Build the constraints as a tuple of dictionaries cons = () # 1. constraints of the 1st kind (eqcons, ieqcons); no jacobian; take # the same extra arguments as the objective function. - cons += tuple({'type': 'eq', 'fun' : c, 'args': args} for c in eqcons) - cons += tuple({'type': 'ineq', 'fun' : c, 'args': args} for c in ieqcons) + cons += tuple({'type': 'eq', 'fun': c, 'args': args} for c in eqcons) + cons += tuple({'type': 'ineq', 'fun': c, 'args': args} for c in ieqcons) # 2. constraints of the 2nd kind (f_eqcons, f_ieqcons) and their jacobian # (fprime_eqcons, fprime_ieqcons); also take the same extra arguments # as the objective function. @@ -267,21 +267,21 @@ def cjac(x, *args): return approx_jacobian(x, con['fun'], epsilon, *args) # update constraints' dictionary - cons[ctype] += ({'fun' : con['fun'], - 'jac' : cjac, + cons[ctype] += ({'fun': con['fun'], + 'jac': cjac, 'args': con.get('args', ())}, ) - exit_modes = {-1 : "Gradient evaluation required (g & a)", - 0 : "Optimization terminated successfully.", - 1 : "Function evaluation required (f & c)", - 2 : "More equality constraints than independent variables", - 3 : "More than 3*n iterations in LSQ subproblem", - 4 : "Inequality constraints incompatible", - 5 : "Singular matrix E in LSQ subproblem", - 6 : "Singular matrix C in LSQ subproblem", - 7 : "Rank-deficient equality constraint subproblem HFTI", - 8 : "Positive directional derivative for linesearch", - 9 : "Iteration limit exceeded"} + exit_modes = {-1: "Gradient evaluation required (g & a)", + 0: "Optimization terminated successfully.", + 1: "Function evaluation required (f & c)", + 2: "More equality constraints than independent variables", + 3: "More than 3*n iterations in LSQ subproblem", + 4: "Inequality constraints incompatible", + 5: "Singular matrix E in LSQ subproblem", + 6: "Singular matrix C in LSQ subproblem", + 7: "Rank-deficient equality constraint subproblem HFTI", + 8: "Positive directional derivative for linesearch", + 9: "Iteration limit exceeded"} # Wrap func feval, func = wrap_function(func, args) @@ -450,8 +450,8 @@ def jieqcon(x, c=10): return array([[1, 1]]) # constraints dictionaries - cons = ({'type': 'eq', 'fun' : feqcon, 'jac' : jeqcon, 'args': (1, )}, - {'type': 'ineq', 'fun' : fieqcon, 'jac' : jieqcon, 'args': (10,)}) + cons = ({'type': 'eq', 'fun': feqcon, 'jac': jeqcon, 'args': (1, )}, + {'type': 'ineq', 'fun': fieqcon, 'jac': jieqcon, 'args': (10,)}) # Bounds constraint problem print(' Bounds constraints '.center(72, '-')) diff --git a/scipy/optimize/tests/test_anneal.py b/scipy/optimize/tests/test_anneal.py index efd52e5f663b..ee6af517d94c 100644 --- a/scipy/optimize/tests/test_anneal.py +++ b/scipy/optimize/tests/test_anneal.py @@ -40,12 +40,12 @@ def anneal_schedule(self, schedule='fast', use_wrapper=False): """ Call anneal algorithm using specified schedule """ n = 0 # index of test function if use_wrapper: - opts = {'upper' : self.upper[n], - 'lower' : self.lower[n], - 'ftol' : 1e-3, - 'maxiter' : self.maxiter, + opts = {'upper': self.upper[n], + 'lower': self.lower[n], + 'ftol': 1e-3, + 'maxiter': self.maxiter, 'schedule': schedule, - 'disp' : False} + 'disp': False} res = minimize(self.fun[n], self.x0[n], method='anneal', options=opts) x, retval = res['x'], res['status'] diff --git a/scipy/optimize/tests/test_nonlin.py b/scipy/optimize/tests/test_nonlin.py index b08728917da2..5b2323d862dd 100644 --- a/scipy/optimize/tests/test_nonlin.py +++ b/scipy/optimize/tests/test_nonlin.py @@ -70,8 +70,8 @@ def F5(x): def F6(x): x1, x2 = x - J0 = np.array([[-4.256 , 14.7], - [0.8394989 , 0.59964207]]) + J0 = np.array([[-4.256, 14.7], + [0.8394989, 0.59964207]]) v = np.array([(x1 + 3) * (x2**5 - 7) + 3*6, np.sin(x2 * np.exp(x1) - 1)]) return -np.linalg.solve(J0, v) diff --git a/scipy/optimize/tests/test_optimize.py b/scipy/optimize/tests/test_optimize.py index a428c7e4e261..9fc1fbdc3037 100644 --- a/scipy/optimize/tests/test_optimize.py +++ b/scipy/optimize/tests/test_optimize.py @@ -236,7 +236,7 @@ def test_neldermead(self, use_wrapper=False): # Ensure that the function behaves the same; this is from Scipy 0.7.0 assert_allclose(self.trace[76:78], - [[0.1928968 , -0.62780447, 0.35166118], + [[0.1928968, -0.62780447, 0.35166118], [0.19572515, -0.63648426, 0.35838135]], atol=1e-14, rtol=1e-7) @@ -360,8 +360,8 @@ def test_l_bfgs_b(self): # Ensure that the function behaves the same; this is from Scipy 0.7.0 assert_allclose(self.trace[3:5], - [[0. , -0.52489628, 0.48753042], - [0. , -0.52489628, 0.48753042]], + [[0., -0.52489628, 0.48753042], + [0., -0.52489628, 0.48753042]], atol=1e-14, rtol=1e-7) def test_l_bfgs_b_numjac(self): diff --git a/scipy/optimize/tests/test_tnc.py b/scipy/optimize/tests/test_tnc.py index a3ea31eef5a1..5e41607ea755 100644 --- a/scipy/optimize/tests/test_tnc.py +++ b/scipy/optimize/tests/test_tnc.py @@ -158,7 +158,7 @@ def test_minimize_tnc3(self): assert_allclose(self.f3(x), self.f3(xopt), atol=1e-8) def test_minimize_tnc4(self): - x0 ,bnds = [1.125, 0.125], [(1, None), (0, None)] + x0,bnds = [1.125, 0.125], [(1, None), (0, None)] xopt = [1, 0] x = optimize.minimize(self.f4, x0, method='TNC', jac=self.g4, bounds=bnds, diff --git a/scipy/optimize/tests/test_zeros.py b/scipy/optimize/tests/test_zeros.py index c5e4d6b29ac8..25e0e0301ab4 100644 --- a/scipy/optimize/tests/test_zeros.py +++ b/scipy/optimize/tests/test_zeros.py @@ -13,7 +13,7 @@ from scipy.optimize._tstutils import functions, fstrings -class TestBasic(TestCase) : +class TestBasic(TestCase): def run_check(self, method, name): a = .5 b = sqrt(3) @@ -54,5 +54,5 @@ def test_deriv_zero_warning(self): dfunc = lambda x: 2*x assert_warns(RuntimeWarning, cc.newton, func, 0.0, dfunc) -if __name__ == '__main__' : +if __name__ == '__main__': run_module_suite() diff --git a/scipy/optimize/tnc.py b/scipy/optimize/tnc.py index 874b21368e54..203f1ad9f229 100644 --- a/scipy/optimize/tnc.py +++ b/scipy/optimize/tnc.py @@ -49,12 +49,12 @@ MSG_ALL = MSG_ITER + MSG_INFO + MSG_VERS + MSG_EXIT MSGS = { - MSG_NONE : "No messages", - MSG_ITER : "One line per iteration", - MSG_INFO : "Informational messages", - MSG_VERS : "Version info", - MSG_EXIT : "Exit reasons", - MSG_ALL : "All messages" + MSG_NONE: "No messages", + MSG_ITER: "One line per iteration", + MSG_INFO: "Informational messages", + MSG_VERS: "Version info", + MSG_EXIT: "Exit reasons", + MSG_ALL: "All messages" } INFEASIBLE = -1 # Infeasible (low > up) @@ -68,15 +68,15 @@ USERABORT = 7 # User requested end of minimization RCSTRINGS = { - INFEASIBLE : "Infeasible (low > up)", - LOCALMINIMUM : "Local minima reach (|pg| ~= 0)", - FCONVERGED : "Converged (|f_n-f_(n-1)| ~= 0)", - XCONVERGED : "Converged (|x_n-x_(n-1)| ~= 0)", - MAXFUN : "Max. number of function evaluations reach", - LSFAIL : "Linear search failed", - CONSTANT : "All lower bounds are equal to the upper bounds", - NOPROGRESS : "Unable to progress", - USERABORT : "User requested end of minimization" + INFEASIBLE: "Infeasible (low > up)", + LOCALMINIMUM: "Local minima reach (|pg| ~= 0)", + FCONVERGED: "Converged (|f_n-f_(n-1)| ~= 0)", + XCONVERGED: "Converged (|x_n-x_(n-1)| ~= 0)", + MAXFUN: "Max. number of function evaluations reach", + LSFAIL: "Linear search failed", + CONSTANT: "All lower bounds are equal to the upper bounds", + NOPROGRESS: "Unable to progress", + USERABORT: "User requested end of minimization" } # Changes to interface made by Travis Oliphant, Apr. 2004 for inclusion in @@ -244,7 +244,7 @@ def fmin_tnc(func, x0, fprime=None, args=(), approx_grad=0, mesg_num = {0:MSG_NONE, 1:MSG_ITER, 2:MSG_INFO, 3:MSG_VERS, 4:MSG_EXIT, 5:MSG_ALL}.get(messages, MSG_ALL) # build options - opts = {'eps' : epsilon, + opts = {'eps': epsilon, 'scale': scale, 'offset': offset, 'mesg_num': mesg_num, diff --git a/scipy/optimize/zeros.py b/scipy/optimize/zeros.py index 15ffef576294..6b072f180714 100644 --- a/scipy/optimize/zeros.py +++ b/scipy/optimize/zeros.py @@ -15,7 +15,7 @@ CONVERGED = 'converged' SIGNERR = 'sign error' CONVERR = 'convergence error' -flag_map = {0 : CONVERGED, -1 : SIGNERR, -2 : CONVERR} +flag_map = {0: CONVERGED, -1: SIGNERR, -2: CONVERR} class RootResults(object): @@ -211,7 +211,7 @@ def bisect(f, a, b, args=(), fsolve : n-dimensional root-finding """ - if type(args) != type(()) : + if type(args) != type(()): args = (args,) r = _zeros._bisect(f,a,b,xtol,maxiter,args,full_output,disp) return results_c(full_output, r) @@ -281,7 +281,7 @@ def ridder(f, a, b, args=(), IEEE Trans. Circuits Systems 26, 979-980, 1979. """ - if type(args) != type(()) : + if type(args) != type(()): args = (args,) r = _zeros._ridder(f,a,b,xtol,maxiter,args,full_output,disp) return results_c(full_output, r) @@ -385,7 +385,7 @@ def brentq(f, a, b, args=(), Section 9.3: "Van Wijngaarden-Dekker-Brent Method." """ - if type(args) != type(()) : + if type(args) != type(()): args = (args,) r = _zeros._brentq(f,a,b,xtol,maxiter,args,full_output,disp) return results_c(full_output, r) @@ -458,7 +458,7 @@ def brenth(f, a, b, args=(), fixed_point : scalar fixed-point finder """ - if type(args) != type(()) : + if type(args) != type(()): args = (args,) r = _zeros._brenth(f,a, b, xtol, maxiter, args, full_output, disp) return results_c(full_output, r) diff --git a/scipy/signal/tests/test_signaltools.py b/scipy/signal/tests/test_signaltools.py index d32a60a74caa..80336b2f3514 100644 --- a/scipy/signal/tests/test_signaltools.py +++ b/scipy/signal/tests/test_signaltools.py @@ -44,7 +44,7 @@ def test_2d_arrays(self): a = [[1,2,3],[3,4,5]] b = [[2,3,4],[4,5,6]] c = convolve(a,b) - d = array([[2 ,7 ,16,17,12], + d = array([[2,7,16,17,12], [10,30,62,58,38], [12,31,58,49,30]]) assert_array_equal(c,d) @@ -78,7 +78,7 @@ class _TestConvolve2d(TestCase): def test_2d_arrays(self): a = [[1,2,3],[3,4,5]] b = [[2,3,4],[4,5,6]] - d = array([[2 ,7 ,16,17,12], + d = array([[2,7,16,17,12], [10,30,62,58,38], [12,31,58,49,30]]) e = convolve2d(a, b) @@ -278,7 +278,7 @@ def test_basic(self): [2.666666667, 4.33333333333, 4.44444444444, 2.8888888888], [2.222222222, 4.4444444444, 5.4444444444, 4.801066874837], [1.33333333333, 3.92735042735, 6.0712560386, 5.0404040404]]) - assert_array_almost_equal(signal.wiener(g), h , decimal=6) + assert_array_almost_equal(signal.wiener(g), h, decimal=6) class TestCSpline1DEval(TestCase): @@ -345,7 +345,7 @@ def test_rank2(self): b = np.array([1, -1]).astype(self.dt) a = np.array([0.5, 0.5]).astype(self.dt) - y_r2_a0 = np.array([[0, 2, 4], [6, 4, 2], [0, 2, 4], [6 ,4 ,2]], + y_r2_a0 = np.array([[0, 2, 4], [6, 4, 2], [0, 2, 4], [6,4,2]], dtype=self.dt) y_r2_a1 = np.array([[0, 2, 0], [6, -4, 6], [12, -10, 12], @@ -382,7 +382,7 @@ def test_rank2_init_cond_a0(self): b = np.array([1, -1]).astype(self.dt) a = np.array([0.5, 0.5]).astype(self.dt) - y_r2_a0_0 = np.array([[1, 3, 5], [5, 3, 1], [1, 3, 5], [5 ,3 ,1]], + y_r2_a0_0 = np.array([[1, 3, 5], [5, 3, 1], [1, 3, 5], [5,3,1]], dtype=self.dt) zf_r = np.array([[-23, -23, -23]], dtype=self.dt) y, zf = lfilter(b, a, x, axis=0, zi=np.ones((1, 3))) @@ -490,8 +490,8 @@ def _setup_rank3(self): y_r = array([[[0., 184., 504., 912., 1360., 888., 472., 160.,], [46., 432., 1062., 1840., 2672., 1698., 864., 266.,], [134., 736., 1662., 2768., 3920., 2418., 1168., 314.,], - [260., 952., 1932., 3056., 4208., 2580., 1240., 332.,] , - [202., 664., 1290., 1984., 2688., 1590., 712., 150.,] , + [260., 952., 1932., 3056., 4208., 2580., 1240., 332.,], + [202., 664., 1290., 1984., 2688., 1590., 712., 150.,], [114., 344., 642., 960., 1280., 726., 296., 38.,]], [[23., 400., 1035., 1832., 2696., 1737., 904., 293.,], @@ -757,7 +757,7 @@ def test_hilbert_axisN(self): yield assert_equal, hilbert(a.T, N=20, axis=0).shape, [20,3] #the next test is just a regression test, #no idea whether numbers make sense - a0hilb = np.array([0.000000000000000e+00-1.72015830311905j , + a0hilb = np.array([0.000000000000000e+00-1.72015830311905j, 1.000000000000000e+00-2.047794505137069j, 1.999999999999999e+00-2.244055555687583j, 3.000000000000000e+00-1.262750302935009j, @@ -772,7 +772,7 @@ def test_hilbert_axisN(self): -1.776356839400251e-16+0.286439612812121j, 3.108624468950438e-16+0.031676888064907j, 1.332267629550188e-16-0.019275656884536j, - -2.360035624836702e-16-0.1652588660287j , + -2.360035624836702e-16-0.1652588660287j, 0.000000000000000e+00-0.332049855010597j, 3.552713678800501e-16-0.403810179797771j, 8.881784197001253e-17-0.751023775297729j, diff --git a/scipy/sparse/linalg/dsolve/linsolve.py b/scipy/sparse/linalg/dsolve/linsolve.py index 63ae3db27a0c..ad12be0ef224 100644 --- a/scipy/sparse/linalg/dsolve/linsolve.py +++ b/scipy/sparse/linalg/dsolve/linsolve.py @@ -128,7 +128,7 @@ def spsolve(A, b, permc_spec=None, use_umfpack=True): b = asarray(b, dtype=A.dtype).reshape(-1) - family = {'d' : 'di', 'D' : 'zi'} + family = {'d': 'di', 'D': 'zi'} umf = umfpack.UmfpackContext(family[A.dtype.char]) x = umf.linsolve(umfpack.UMFPACK_A, A, b, autoTranspose=True) @@ -345,7 +345,7 @@ def factorized(A): raise ValueError("convert matrix data to double, please, using" " .astype(), or set linsolve.useUmfpack = False") - family = {'d' : 'di', 'D' : 'zi'} + family = {'d': 'di', 'D': 'zi'} umf = umfpack.UmfpackContext(family[A.dtype.char]) # Make LU decomposition. diff --git a/scipy/sparse/linalg/dsolve/umfpack/tests/try_umfpack.py b/scipy/sparse/linalg/dsolve/umfpack/tests/try_umfpack.py index 7b5a689d5433..d6e050992157 100644 --- a/scipy/sparse/linalg/dsolve/umfpack/tests/try_umfpack.py +++ b/scipy/sparse/linalg/dsolve/umfpack/tests/try_umfpack.py @@ -70,7 +70,7 @@ def read_triplet2(fd): return mtx -formatMap = {'triplet' : read_triplet} +formatMap = {'triplet': read_triplet} ## # 05.12.2005, c diff --git a/scipy/sparse/linalg/dsolve/umfpack/umfpack.py b/scipy/sparse/linalg/dsolve/umfpack/umfpack.py index 2d8b3a95de43..ffa7e6a70464 100644 --- a/scipy/sparse/linalg/dsolve/umfpack/umfpack.py +++ b/scipy/sparse/linalg/dsolve/umfpack/umfpack.py @@ -189,21 +189,21 @@ def updateDictWithVars(adict, module, pattern, group=None): locals().update(umfDefines) umfStatus = { - UMFPACK_OK : 'UMFPACK_OK', - UMFPACK_WARNING_singular_matrix : 'UMFPACK_WARNING_singular_matrix', - UMFPACK_WARNING_determinant_underflow : 'UMFPACK_WARNING_determinant_underflow', - UMFPACK_WARNING_determinant_overflow : 'UMFPACK_WARNING_determinant_overflow', - UMFPACK_ERROR_out_of_memory : 'UMFPACK_ERROR_out_of_memory', - UMFPACK_ERROR_invalid_Numeric_object : 'UMFPACK_ERROR_invalid_Numeric_object', - UMFPACK_ERROR_invalid_Symbolic_object : 'UMFPACK_ERROR_invalid_Symbolic_object', - UMFPACK_ERROR_argument_missing : 'UMFPACK_ERROR_argument_missing', - UMFPACK_ERROR_n_nonpositive : 'UMFPACK_ERROR_n_nonpositive', - UMFPACK_ERROR_invalid_matrix : 'UMFPACK_ERROR_invalid_matrix', - UMFPACK_ERROR_different_pattern : 'UMFPACK_ERROR_different_pattern', - UMFPACK_ERROR_invalid_system : 'UMFPACK_ERROR_invalid_system', - UMFPACK_ERROR_invalid_permutation : 'UMFPACK_ERROR_invalid_permutation', - UMFPACK_ERROR_internal_error : 'UMFPACK_ERROR_internal_error', - UMFPACK_ERROR_file_IO : 'UMFPACK_ERROR_file_IO', + UMFPACK_OK: 'UMFPACK_OK', + UMFPACK_WARNING_singular_matrix: 'UMFPACK_WARNING_singular_matrix', + UMFPACK_WARNING_determinant_underflow: 'UMFPACK_WARNING_determinant_underflow', + UMFPACK_WARNING_determinant_overflow: 'UMFPACK_WARNING_determinant_overflow', + UMFPACK_ERROR_out_of_memory: 'UMFPACK_ERROR_out_of_memory', + UMFPACK_ERROR_invalid_Numeric_object: 'UMFPACK_ERROR_invalid_Numeric_object', + UMFPACK_ERROR_invalid_Symbolic_object: 'UMFPACK_ERROR_invalid_Symbolic_object', + UMFPACK_ERROR_argument_missing: 'UMFPACK_ERROR_argument_missing', + UMFPACK_ERROR_n_nonpositive: 'UMFPACK_ERROR_n_nonpositive', + UMFPACK_ERROR_invalid_matrix: 'UMFPACK_ERROR_invalid_matrix', + UMFPACK_ERROR_different_pattern: 'UMFPACK_ERROR_different_pattern', + UMFPACK_ERROR_invalid_system: 'UMFPACK_ERROR_invalid_system', + UMFPACK_ERROR_invalid_permutation: 'UMFPACK_ERROR_invalid_permutation', + UMFPACK_ERROR_internal_error: 'UMFPACK_ERROR_internal_error', + UMFPACK_ERROR_file_IO: 'UMFPACK_ERROR_file_IO', } umfSys = [ @@ -225,14 +225,14 @@ def updateDictWithVars(adict, module, pattern, group=None): # Real, complex. umfSys_transposeMap = [ - {UMFPACK_A : UMFPACK_At, - UMFPACK_At : UMFPACK_A, - UMFPACK_Aat : UMFPACK_A}, - {UMFPACK_A : UMFPACK_Aat, - UMFPACK_Aat : UMFPACK_A} + {UMFPACK_A: UMFPACK_At, + UMFPACK_At: UMFPACK_A, + UMFPACK_Aat: UMFPACK_A}, + {UMFPACK_A: UMFPACK_Aat, + UMFPACK_Aat: UMFPACK_A} ] -umfFamilyTypes = {'di' : int, 'dl' : int, 'zi' : int, 'zl' : int} +umfFamilyTypes = {'di': int, 'dl': int, 'zi': int, 'zl': int} umfRealTypes = ('di', 'dl') umfComplexTypes = ('zi', 'zl') diff --git a/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py b/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py index 6d0cf5b775f1..1dfac801504e 100644 --- a/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py +++ b/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py @@ -267,8 +267,8 @@ def __init__(self): self.eigs = eigsh self.which = ['LM', 'SM', 'LA', 'SA', 'BE'] self.mattypes = [csr_matrix, aslinearoperator, np.asarray] - self.sigmas_modes = {None : ['normal'], - 0.5 : ['normal', 'buckling', 'cayley']} + self.sigmas_modes = {None: ['normal'], + 0.5: ['normal', 'buckling', 'cayley']} #generate matrices # these should all be float32 so that the eigenvalues @@ -318,9 +318,9 @@ def __init__(self): self.eigs = eigs self.which = ['LM', 'LR', 'LI']# , 'SM', 'LR', 'SR', 'LI', 'SI'] self.mattypes = [csr_matrix, aslinearoperator, np.asarray] - self.sigmas_OPparts = {None : [None], - 0.1 : ['r'], - 0.1 + 0.1j : ['r', 'i']} + self.sigmas_OPparts = {None: [None], + 0.1: ['r'], + 0.1 + 0.1j: ['r', 'i']} #generate matrices # these should all be float32 so that the eigenvalues diff --git a/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py b/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py index 3f075cca37c3..5a6fffce4eb8 100644 --- a/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py +++ b/scipy/sparse/linalg/eigen/lobpcg/lobpcg.py @@ -556,7 +556,7 @@ def lobpcg(A, X, Y = np.eye(n, 3) # X = sp.rand( n, 3 ) - xfile = {100 : 'X.txt', 1000 : 'X2.txt', 10000 : 'X3.txt'} + xfile = {100: 'X.txt', 1000: 'X2.txt', 10000: 'X3.txt'} X = np.fromfile(xfile[n], dtype=np.float64, sep=' ') X.shape = (n, 3) diff --git a/scipy/sparse/linalg/isolve/minres.py b/scipy/sparse/linalg/isolve/minres.py index 5b77111655e0..d4791bdb88fe 100644 --- a/scipy/sparse/linalg/isolve/minres.py +++ b/scipy/sparse/linalg/isolve/minres.py @@ -249,42 +249,42 @@ def minres(A, b, x0=None, shift=0.0, tol=1e-5, maxiter=None, xtype=None, if istop == 0: t1 = 1 + test1 # These tests work if tol < eps t2 = 1 + test2 - if t2 <= 1 : + if t2 <= 1: istop = 2 - if t1 <= 1 : + if t1 <= 1: istop = 1 - if itn >= maxiter : + if itn >= maxiter: istop = 6 - if Acond >= 0.1/eps : + if Acond >= 0.1/eps: istop = 4 - if epsx >= beta1 : + if epsx >= beta: istop = 3 #if rnorm <= epsx : istop = 2 #if rnorm <= epsr : istop = 1 - if test2 <= tol : + if test2 <= tol: istop = 2 - if test1 <= tol : + if test1 <= tol: istop = 1 # See if it is time to print something. prnt = False - if n <= 40 : + if n <= 40: prnt = True - if itn <= 10 : + if itn <= 10: prnt = True - if itn >= maxiter-10 : + if itn >= maxiter-10: prnt = True - if itn % 10 == 0 : + if itn % 10 == 0: prnt = True - if qrnorm <= 10*epsx : + if qrnorm <= 10*epsx: prnt = True - if qrnorm <= 10*epsr : + if qrnorm <= 10*epsr: prnt = True - if Acond <= 1e-2/eps : + if Acond <= 1e-2/eps: prnt = True - if istop != 0 : + if istop != 0: prnt = True if show and prnt: diff --git a/scipy/sparse/linalg/isolve/tests/test_iterative.py b/scipy/sparse/linalg/isolve/tests/test_iterative.py index 99b737548b1f..3c73401cc933 100644 --- a/scipy/sparse/linalg/isolve/tests/test_iterative.py +++ b/scipy/sparse/linalg/isolve/tests/test_iterative.py @@ -262,7 +262,7 @@ def test_leftright_precond(self): n = 100 dat = ones(n) - A = spdiags([-2*dat, 4*dat, -dat], [-1,0,1] ,n,n) + A = spdiags([-2*dat, 4*dat, -dat], [-1,0,1],n,n) b = arange(n,dtype='d') L = spdiags([-dat/2, dat], [-1,0], n, n) diff --git a/scipy/sparse/tests/test_base.py b/scipy/sparse/tests/test_base.py index 6874839a942d..af28404f2ee2 100644 --- a/scipy/sparse/tests/test_base.py +++ b/scipy/sparse/tests/test_base.py @@ -326,11 +326,11 @@ def test_astype(self): def test_asfptype(self): A = self.spmatrix(arange(6,dtype='int32').reshape(2,3)) - assert_equal(A.dtype , np.dtype('int32')) + assert_equal(A.dtype, np.dtype('int32')) assert_equal(A.asfptype().dtype, np.dtype('float64')) assert_equal(A.asfptype().format, A.format) - assert_equal(A.astype('int16').asfptype().dtype , np.dtype('float32')) - assert_equal(A.astype('complex128').asfptype().dtype , np.dtype('complex128')) + assert_equal(A.astype('int16').asfptype().dtype, np.dtype('float32')) + assert_equal(A.astype('complex128').asfptype().dtype, np.dtype('complex128')) B = A.asfptype() C = B.asfptype() diff --git a/scipy/special/tests/test_basic.py b/scipy/special/tests/test_basic.py index 8dab8b6d2306..74e987c45987 100644 --- a/scipy/special/tests/test_basic.py +++ b/scipy/special/tests/test_basic.py @@ -711,7 +711,7 @@ def test_bi_zeros(self): bia = (array([-1.17371322, -3.2710930]), array([-2.29443968, -4.07315509]), array([-0.45494438, 0.39652284]), - array([0.60195789 , -0.76031014])) + array([0.60195789, -0.76031014])) assert_array_almost_equal(bi,bia,4) def test_ai_zeros(self): @@ -2219,20 +2219,20 @@ def test_clpmn(self): def test_lpmn(self): lp = special.lpmn(0,2,.5) - assert_array_almost_equal(lp,(array([[1.00000 , + assert_array_almost_equal(lp,(array([[1.00000, 0.50000, -0.12500]]), - array([[0.00000 , - 1.00000 , + array([[0.00000, + 1.00000, 1.50000]])),4) def test_lpn(self): lpnf = special.lpn(2,.5) - assert_array_almost_equal(lpnf,(array([1.00000 , + assert_array_almost_equal(lpnf,(array([1.00000, 0.50000, -0.12500]), - array([0.00000 , - 1.00000 , + array([0.00000, + 1.00000, 1.50000])),4) def test_lpmv(self): @@ -2269,7 +2269,7 @@ def test_lqmn_shape(self): def test_lqn(self): lqf = special.lqn(2,.5) assert_array_almost_equal(lqf,(array([0.5493, -0.7253, -0.8187]), - array([1.3333, 1.216 , -0.8427])),4) + array([1.3333, 1.216, -0.8427])),4) class TestMathieu(TestCase): diff --git a/scipy/special/tests/test_logit.py b/scipy/special/tests/test_logit.py index 5bceb4d5fb75..8d6e1cebfd78 100644 --- a/scipy/special/tests/test_logit.py +++ b/scipy/special/tests/test_logit.py @@ -26,7 +26,7 @@ def test_float32(self): expected = np.array([-np.inf, -2.07944155, -1.25276291, -0.69314718, -0.22314353, 0.22314365, - 0.6931473 , 1.25276303, + 0.6931473, 1.25276303, 2.07944155, np.inf], dtype=np.float32) self.check_logit_out('f4', expected) @@ -61,14 +61,14 @@ def test_float32(self): expected = np.array([0.01798621, 0.04265125, 0.09777259, 0.20860852, 0.39068246, 0.60931754, - 0.79139149, 0.9022274 , + 0.79139149, 0.9022274, 0.95734876, 0.98201376], dtype=np.float32) self.check_expit_out('f4',expected) def test_float64(self): expected = np.array([0.01798621, 0.04265125, - 0.0977726 , 0.20860853, + 0.0977726, 0.20860853, 0.39068246, 0.60931754, - 0.79139147, 0.9022274 , + 0.79139147, 0.9022274, 0.95734875, 0.98201379]) self.check_expit_out('f8', expected) diff --git a/scipy/stats/distributions.py b/scipy/stats/distributions.py index 2f28d1131157..a979953d02a5 100644 --- a/scipy/stats/distributions.py +++ b/scipy/stats/distributions.py @@ -3261,7 +3261,7 @@ def _ppf(self, q, c): return where((c == 0)*(x == x),x,-expm1(-c*x)/c) def _stats(self,c): - g = lambda n : gam(n*c+1) + g = lambda n: gam(n*c+1) g1 = g(1) g2 = g(2) g3 = g(3) @@ -4193,7 +4193,7 @@ def _rvs(self, s): def _pdf(self, x, s): return exp(self._logpdf(x, s)) def _logpdf(self, x, s): - return -log(x)**2 / (2*s**2) + np.where(x == 0 , 0, - log(s*x*sqrt(2*pi))) + return -log(x)**2 / (2*s**2) + np.where(x == 0, 0, - log(s*x*sqrt(2*pi))) def _cdf(self, x, s): return norm.cdf(log(x)/s) def _ppf(self, q, s): diff --git a/scipy/stats/stats.py b/scipy/stats/stats.py index 46bf4c7f1046..91494c657720 100644 --- a/scipy/stats/stats.py +++ b/scipy/stats/stats.py @@ -3449,7 +3449,7 @@ def kstest(rvs, cdf, args=(), N=20, alternative='two-sided', mode='approx', return D, distributions.kstwobign.sf(D*np.sqrt(N)) if mode == 'approx': pval_two = distributions.kstwobign.sf(D*np.sqrt(N)) - if N > 2666 or pval_two > 0.80 - N*0.3/1000.0 : + if N > 2666 or pval_two > 0.80 - N*0.3/1000.0: return D, distributions.kstwobign.sf(D*np.sqrt(N)) else: return D, distributions.ksone.sf(D,N)*2 diff --git a/scipy/stats/tests/test_distributions.py b/scipy/stats/tests/test_distributions.py index 52b9913d561d..5284037f8730 100644 --- a/scipy/stats/tests/test_distributions.py +++ b/scipy/stats/tests/test_distributions.py @@ -348,7 +348,7 @@ def test_rvs(self): class TestDLaplace(TestCase): def test_rvs(self): - vals = stats.dlaplace.rvs(1.5 , size=(2, 50)) + vals = stats.dlaplace.rvs(1.5, size=(2, 50)) assert_(numpy.shape(vals) == (2, 50)) assert_(vals.dtype.char in typecodes['AllInteger']) val = stats.dlaplace.rvs(1.5) @@ -998,7 +998,7 @@ def test_powerlaw_stats(): which can be rearranged to gamma_2 = 6 * (a**3 - a**2 - 6*a + 2) / (a*(a+3)*(a+4)) """ - cases = [(1.0, (0.5, 1./12 , 0.0, -1.2)), + cases = [(1.0, (0.5, 1./12, 0.0, -1.2)), (2.0, (2./3, 2./36, -0.56568542494924734, -0.6))] for a, exact_mvsk in cases: mvsk = stats.powerlaw.stats(a, moments="mvsk") @@ -1009,14 +1009,14 @@ def test_ksone_fit_freeze(): #Regression test for ticket #1638. d = np.array( [-0.18879233, 0.15734249, 0.18695107, 0.27908787, -0.248649, - -0.2171497 , 0.12233512, 0.15126419, 0.03119282, 0.4365294 , + -0.2171497, 0.12233512, 0.15126419, 0.03119282, 0.4365294, 0.08930393, -0.23509903, 0.28231224, -0.09974875, -0.25196048, - 0.11102028, 0.1427649 , 0.10176452, 0.18754054, 0.25826724, - 0.05988819, 0.0531668 , 0.21906056, 0.32106729, 0.2117662 , + 0.11102028, 0.1427649, 0.10176452, 0.18754054, 0.25826724, + 0.05988819, 0.0531668, 0.21906056, 0.32106729, 0.2117662, 0.10886442, 0.09375789, 0.24583286, -0.22968366, -0.07842391, - -0.31195432, -0.21271196, 0.1114243 , -0.13293002, 0.01331725, + -0.31195432, -0.21271196, 0.1114243, -0.13293002, 0.01331725, -0.04330977, -0.09485776, -0.28434547, 0.22245721, -0.18518199, - -0.10943985, -0.35243174, 0.06897665, -0.03553363, -0.0701746 , + -0.10943985, -0.35243174, 0.06897665, -0.03553363, -0.0701746, -0.06037974, 0.37670779, -0.21684405]) olderr = np.seterr(invalid='ignore') diff --git a/scipy/stats/tests/test_mstats_basic.py b/scipy/stats/tests/test_mstats_basic.py index 650c6291003f..73b20231fb75 100644 --- a/scipy/stats/tests/test_mstats_basic.py +++ b/scipy/stats/tests/test_mstats_basic.py @@ -287,14 +287,14 @@ class TestMoments(TestCase): # http://www.mathworks.com/access/helpdesk/help/toolbox/stats/skewness.shtml # Note that both test cases came from here. testcase = [1,2,3,4] - testmathworks = ma.fix_invalid([1.165 , 0.6268, 0.0751, 0.3516, -0.6965, + testmathworks = ma.fix_invalid([1.165, 0.6268, 0.0751, 0.3516, -0.6965, np.nan]) testcase_2d = ma.array( np.array([[0.05245846, 0.50344235, 0.86589117, 0.36936353, 0.46961149], [0.11574073, 0.31299969, 0.45925772, 0.72618805, 0.75194407], [0.67696689, 0.91878127, 0.09769044, 0.04645137, 0.37615733], [0.05903624, 0.29908861, 0.34088298, 0.66216337, 0.83160998], - [0.64619526, 0.94894632, 0.27855892, 0.0706151 , 0.39962917]]), + [0.64619526, 0.94894632, 0.27855892, 0.0706151, 0.39962917]]), mask=np.array([[True, False, False, True, False], [True, True, True, False, True], [False, False, False, False, False], @@ -435,8 +435,8 @@ def test_zmap(self): (testcase[i]-mean(testcase,axis=0))/sqrt(var(testcase)*3/4) """ y = mstats.zmap(self.testcase, self.testcase) - desired_unmaskedvals = ([-1.3416407864999, -0.44721359549996 , - 0.44721359549996 , 1.3416407864999]) + desired_unmaskedvals = ([-1.3416407864999, -0.44721359549996, + 0.44721359549996, 1.3416407864999]) assert_array_almost_equal(desired_unmaskedvals, y.data[y.mask == False], decimal=12) @@ -446,8 +446,8 @@ def test_zscore(self): (testcase[i]-mean(testcase,axis=0))/sqrt(var(testcase)*3/4) """ y = mstats.zscore(self.testcase) - desired = ma.fix_invalid([-1.3416407864999, -0.44721359549996 , - 0.44721359549996 , 1.3416407864999, np.nan]) + desired = ma.fix_invalid([-1.3416407864999, -0.44721359549996, + 0.44721359549996, 1.3416407864999, np.nan]) assert_almost_equal(desired, y, decimal=12) diff --git a/scipy/stats/tests/test_stats.py b/scipy/stats/tests/test_stats.py index b62b2bd4aef3..c20962fa78b7 100644 --- a/scipy/stats/tests/test_stats.py +++ b/scipy/stats/tests/test_stats.py @@ -814,14 +814,14 @@ def test_weighting(self): basic_tests = ((self.low_values, (np.array([4.0, 0.0, 4.5, -0.9, 0.0, 0.3,110.2, 0.0, 0.0, 42.0]), 0.2, 0.1, 0)), - (self.high_range, (np.array([9.6, 0. , -1. , 0. , 0. , - 0. ,145.2, 0. , 0.3, 7.]), + (self.high_range, (np.array([9.6, 0., -1., 0., 0., + 0.,145.2, 0., 0.3, 7.]), 2.0, 9.3, 0)), - (self.low_range, (np.array([2.4, 0. , 0. , 0. , 0. , - 2. , 40. , 0. , 103.2, 13.5]), + (self.low_range, (np.array([2.4, 0., 0., 0., 0., + 2., 40., 0., 103.2, 13.5]), 2.0, 0.11, 0)), - (self.few_values, (np.array([4.5, 0. , 0.1, 0. , 0. , 0. , - 0. , 1. , 0. , 3.]), + (self.few_values, (np.array([4.5, 0., 0.1, 0., 0., 0., + 0., 1., 0., 3.]), -1., 0.4, 0)), ) @@ -1038,8 +1038,8 @@ def test_fraction(self): assert_equal(scoreatperc(list(range(10)), 50), 4.5) assert_equal(scoreatperc(list(range(10)), 50, (2,7)), 4.5) assert_equal(scoreatperc(list(range(100)), 50, limit=(1, 8)), 4.5) - assert_equal(scoreatperc(np.array([1, 10 ,100]), 50, (10,100)), 55) - assert_equal(scoreatperc(np.array([1, 10 ,100]), 50, (1,10)), 5.5) + assert_equal(scoreatperc(np.array([1, 10,100]), 50, (10,100)), 55) + assert_equal(scoreatperc(np.array([1, 10,100]), 50, (1,10)), 5.5) # explicitly specify interpolation_method 'fraction' (the default) assert_equal(scoreatperc(list(range(10)), 50, interpolation_method='fraction'), @@ -1050,10 +1050,10 @@ def test_fraction(self): assert_equal(scoreatperc(list(range(100)), 50, limit=(1, 8), interpolation_method='fraction'), 4.5) - assert_equal(scoreatperc(np.array([1, 10 ,100]), 50, (10, 100), + assert_equal(scoreatperc(np.array([1, 10,100]), 50, (10, 100), interpolation_method='fraction'), 55) - assert_equal(scoreatperc(np.array([1, 10 ,100]), 50, (1,10), + assert_equal(scoreatperc(np.array([1, 10,100]), 50, (1,10), interpolation_method='fraction'), 5.5) @@ -1150,7 +1150,7 @@ def test_zmap(self): (testcase[i]-mean(testcase,axis=0))/sqrt(var(testcase)*3/4) """ y = stats.zmap(self.testcase,self.testcase) - desired = ([-1.3416407864999, -0.44721359549996 , 0.44721359549996 , 1.3416407864999]) + desired = ([-1.3416407864999, -0.44721359549996, 0.44721359549996, 1.3416407864999]) assert_array_almost_equal(desired,y,decimal=12) def test_zmap_axis(self): @@ -1198,7 +1198,7 @@ def test_zscore(self): (testcase[i]-mean(testcase,axis=0))/sqrt(var(testcase)*3/4) """ y = stats.zscore(self.testcase) - desired = ([-1.3416407864999, -0.44721359549996 , 0.44721359549996 , 1.3416407864999]) + desired = ([-1.3416407864999, -0.44721359549996, 0.44721359549996, 1.3416407864999]) assert_array_almost_equal(desired,y,decimal=12) def test_zscore_axis(self): @@ -1252,7 +1252,7 @@ class TestMoments(TestCase): Note that both test cases came from here. """ testcase = [1,2,3,4] - testmathworks = [1.165 , 0.6268, 0.0751, 0.3516, -0.6965] + testmathworks = [1.165, 0.6268, 0.0751, 0.3516, -0.6965] def test_moment(self): """ mean((testcase-mean(testcase))**power,axis=0),axis=0))**power))""" @@ -1918,7 +1918,7 @@ def test_2daxis0(self): def test_2daxis1(self): ''' Test a 2d list with axis=1''' a = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]] - b = np.array([19.2 , 63.03939962, 103.80078637]) + b = np.array([19.2, 63.03939962, 103.80078637]) self.do(a, b, axis=1) def test_2dmatrixdaxis0(self): ''' Test a 2d list with axis=0''' @@ -1928,7 +1928,7 @@ def test_2dmatrixdaxis0(self): def test_2dmatrixaxis1(self): ''' Test a 2d list with axis=1''' a = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]] - b = np.matrix([[19.2 , 63.03939962, 103.80078637]]).T + b = np.matrix([[19.2, 63.03939962, 103.80078637]]).T self.do(np.matrix(a), b, axis=1) ## def test_dtype(self): ## ''' Test a 1d list with a new dtype''' @@ -1985,7 +1985,7 @@ def test_2dma(self): def test_2daxis0(self): ''' Test a 2d list with axis=0''' a = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]] - b = np.array([35.56893304, 49.32424149, 61.3579244 , 72.68482371]) + b = np.array([35.56893304, 49.32424149, 61.3579244, 72.68482371]) self.do(a, b, axis=0) def test_2daxis1(self): ''' Test a 2d list with axis=1''' @@ -1995,7 +1995,7 @@ def test_2daxis1(self): def test_2dmatrixdaxis0(self): ''' Test a 2d list with axis=0''' a = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]] - b = np.matrix([[35.56893304, 49.32424149, 61.3579244 , 72.68482371]]) + b = np.matrix([[35.56893304, 49.32424149, 61.3579244, 72.68482371]]) self.do(np.matrix(a), b, axis=0) def test_2dmatrixaxis1(self): ''' Test a 2d list with axis=1''' diff --git a/scipy/weave/accelerate_tools.py b/scipy/weave/accelerate_tools.py index 450a4c663dfe..cb29f55a5299 100644 --- a/scipy/weave/accelerate_tools.py +++ b/scipy/weave/accelerate_tools.py @@ -228,8 +228,8 @@ class XRange { typedefs = { - int : Integer, - float : Double, + int: Integer, + float: Double, str: String, (np.ndarray,1,int): IntegerVector, (np.ndarray,2,int): Integermatrix, @@ -237,7 +237,7 @@ class XRange { (np.ndarray,2,np.long): Longmatrix, (np.ndarray,1,float): DoubleVector, (np.ndarray,2,float): Doublematrix, - XRangeType : XRange, + XRangeType: XRange, } import math diff --git a/scipy/weave/bytecodecompiler.py b/scipy/weave/bytecodecompiler.py index db667052eaa8..8de71c3994d7 100644 --- a/scipy/weave/bytecodecompiler.py +++ b/scipy/weave/bytecodecompiler.py @@ -253,7 +253,7 @@ def evaluate(self, pc,code): symbols = {0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal', 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in', 8: 'is', 9: 'is not', 10: 'exe match', - 11 : 'bad', + 11: 'bad', } def cmp_op(self,opname): return self.symbols[opname] diff --git a/tox.ini b/tox.ini index f0fe336a4a49..1989bfc60384 100644 --- a/tox.ini +++ b/tox.ini @@ -38,5 +38,5 @@ commands=python {toxinidir}/tools/test-installed-scipy.py {posargs:} [pep8] max_line_length=79 statistics = True -ignore = E12,E203,E221,E226,E231,E241,E261,E301,E501,E712,E721 +ignore = E12,E221,E226,E231,E241,E261,E301,E501,E712,E721 exclude = scipy/sparse/linalg/dsolve/umfpack/_umfpack.py,scipy/sparse/sparsetools/bsr.py,scipy/sparse/sparsetools/coo.py,scipy/sparse/sparsetools/csc.py,scipy/sparse/sparsetools/csgraph.py,scipy/sparse/sparsetools/csr.py,scipy/sparse/sparsetools/dia.py,scipy/__config__.py