Skip to content

Commit

Permalink
PEP8: Fix E302 expected 2 blank lines, found 1
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Apr 14, 2013
1 parent f611c76 commit 5d565c0
Show file tree
Hide file tree
Showing 338 changed files with 1,758 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scipy/_build_utils/_fortran.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import sys


def _uses_veclib(info):
r_accelerate = re.compile("Accelerate|vecLib")

Expand All @@ -11,6 +12,7 @@ def _uses_veclib(info):

return False


def _uses_mkl(info):
r_mkl = re.compile("mkl_core")

Expand All @@ -21,6 +23,7 @@ def _uses_mkl(info):

return False


def needs_g77_abi_wrapper(info):
"""Returns true if g77 ABI wrapper must be used."""
if _uses_veclib(info):
Expand Down
1 change: 1 addition & 0 deletions scipy/cluster/doc/ex1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from scipy import *
from scipy.cluster import vq


def cluster_data(data,cluster_cnt,iter=20,thresh=1e-5):
""" Group data into a number of common clusters
Expand Down
4 changes: 4 additions & 0 deletions scipy/cluster/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@ def leaves_list(Z):
_drotationsortedkeys = list(_drotation.keys())
_drotationsortedkeys.sort()


def _remove_dups(L):
"""
Removes duplicates AND preserves the original order of the elements.
Expand All @@ -1682,16 +1683,19 @@ def _remove_dups(L):
L2.append(i)
return L2


def _get_tick_text_size(p):
for k in _dtextsortedkeys:
if p <= k:
return _dtextsizes[k]


def _get_tick_rotation(p):
for k in _drotationsortedkeys:
if p <= k:
return _drotation[k]


def _plot_dendrogram(icoords, dcoords, ivl, p, n, mh, orientation,
no_labels, color_list, leaf_font_size=None,
leaf_rotation=None, contraction_marks=None):
Expand Down
1 change: 1 addition & 0 deletions scipy/cluster/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
else:
DEFINE_MACROS = []


def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
config = Configuration('cluster', parent_package, top_path)
Expand Down
1 change: 1 addition & 0 deletions scipy/cluster/setupscons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from os.path import join


def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
config = Configuration('cluster', parent_package, top_path)
Expand Down
1 change: 1 addition & 0 deletions scipy/cluster/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def test_fcluster_maxclusts_4(self):
T = fcluster(Z, criterion='maxclust', t=4)
self.assertTrue(is_isomorphic(T, expectedT))


class TestLeaders(TestCase):
def test_leaders_single(self):
"Tests leaders using a flat clustering generated by single linkage."
Expand Down
2 changes: 2 additions & 0 deletions scipy/cluster/tests/test_vq.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

LABEL1 = np.array([0, 1, 2, 2, 2, 2, 1, 2, 1, 1, 1])


class TestVq(TestCase):
def test_py_vq(self):
initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
Expand Down Expand Up @@ -91,6 +92,7 @@ def test__vq_sametype(self):
b = a.astype(float)
assert_raises(ValueError, _vq.vq, a, b)


class TestKMean(TestCase):
def test_large_features(self):
# Generate a data set with large values, and run kmeans on it to
Expand Down
3 changes: 3 additions & 0 deletions scipy/cluster/tests/vq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from scipy.cluster import vq


def python_vq(all_data,code_book):
import time
t1 = time.time()
Expand All @@ -26,6 +27,7 @@ def python_vq(all_data,code_book):

return codes1,dist1


def read_data(name):
f = open(name,'r')
data = []
Expand All @@ -34,6 +36,7 @@ def read_data(name):
f.close()
return array(data)


def main():
np.random.seed((1000,1000))
Ncodes = 40
Expand Down
14 changes: 14 additions & 0 deletions scipy/cluster/vq.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@
std, mean
import numpy as np


class ClusterError(Exception):
pass


def whiten(obs):
"""
Normalize a group of observations on a per feature basis.
Expand Down Expand Up @@ -131,6 +133,7 @@ def whiten(obs):
std_dev = std(obs, axis=0)
return obs / std_dev


def vq(obs, code_book):
"""
Assign codes from a code book to observations.
Expand Down Expand Up @@ -203,6 +206,7 @@ def vq(obs, code_book):
results = py_vq(obs, code_book)
return results


def py_vq(obs, code_book):
""" Python version of vq algorithm.
Expand Down Expand Up @@ -264,6 +268,7 @@ def py_vq(obs, code_book):

return code, sqrt(min_dist)


def _py_vq_1d(obs, code_book):
""" Python version of vq algorithm for rank 1 only.
Expand Down Expand Up @@ -296,6 +301,7 @@ def _py_vq_1d(obs, code_book):

return code, sqrt(min_dist)


def py_vq2(obs, code_book):
"""2nd Python version of vq algorithm.
Expand Down Expand Up @@ -344,6 +350,7 @@ def py_vq2(obs, code_book):
# much difference.
return code, min_dist


def _kmeans(obs, guess, thresh=1e-5):
""" "raw" version of k-means.
Expand Down Expand Up @@ -402,6 +409,7 @@ def _kmeans(obs, guess, thresh=1e-5):
#print avg_dist
return code_book, avg_dist[-1]


def kmeans(obs, k_or_guess, iter=20, thresh=1e-5):
"""
Performs k-means on a set of observation vectors forming k clusters.
Expand Down Expand Up @@ -516,6 +524,7 @@ def kmeans(obs, k_or_guess, iter=20, thresh=1e-5):
result = best_book, best_dist
return result


def _kpoints(data, k):
"""Pick k points at random in data (one row = one observation).
Expand All @@ -542,6 +551,7 @@ def _kpoints(data, k):

return x


def _krandinit(data, k):
"""Returns k samples of a random variable which parameters depend on data.
Expand Down Expand Up @@ -583,18 +593,21 @@ def init_rankn(data):

_valid_init_meth = {'random': _krandinit, 'points': _kpoints}


def _missing_warn():
"""Print a warning when called."""
warnings.warn("One of the clusters is empty. "
"Re-run kmean with a different initialization.")


def _missing_raise():
"""raise a ClusterError when called."""
raise ClusterError("One of the clusters is empty. "
"Re-run kmean with a different initialization.")

_valid_miss_meth = {'warn': _missing_warn, 'raise': _missing_raise}


def kmeans2(data, k, iter=10, thresh=1e-5, minit='random',
missing='warn'):
"""
Expand Down Expand Up @@ -696,6 +709,7 @@ def kmeans2(data, k, iter=10, thresh=1e-5, minit='random',

return _kmeans2(data, clusters, iter, nc, _valid_miss_meth[missing])


def _kmeans2(data, code, niter, nc, missing):
""" "raw" version of kmeans2. Do not use directly.
Expand Down
7 changes: 7 additions & 0 deletions scipy/constants/codata.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@

physical_constants = {}


def parse_constants(d):
constants = {}
for line in d.split('\n'):
Expand Down Expand Up @@ -843,15 +844,18 @@ def parse_constants(d):
if 'momentum' in k:
_aliases[k] = k.replace('momentum', 'mom.um')


class ConstantWarning(DeprecationWarning):
"""Accessing a constant no longer in current CODATA data set"""
pass


def _check_obsolete(key):
if key in _obsolete_constants and key not in _aliases:
warnings.warn("Constant '%s' is not in current %s data set" % (
key, _current_codata), ConstantWarning)


def value(key) :
"""
Value in physical_constants indexed by key
Expand Down Expand Up @@ -881,6 +885,7 @@ def value(key) :
_check_obsolete(key)
return physical_constants[key][0]


def unit(key) :
"""
Unit in physical_constants indexed by key
Expand Down Expand Up @@ -910,6 +915,7 @@ def unit(key) :
_check_obsolete(key)
return physical_constants[key][1]


def precision(key) :
"""
Relative precision in physical_constants indexed by key
Expand Down Expand Up @@ -939,6 +945,7 @@ def precision(key) :
_check_obsolete(key)
return physical_constants[key][2] / physical_constants[key][0]


def find(sub=None, disp=False):
"""
Return list of codata.physical_constant keys containing a given string.
Expand Down
8 changes: 8 additions & 0 deletions scipy/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@

#functions for conversions that are not linear


def C2K(C):
"""
Convert Celsius to Kelvin
Expand Down Expand Up @@ -200,6 +201,7 @@ def C2K(C):
"""
return _np.asanyarray(C) + zero_Celsius


def K2C(K):
"""
Convert Kelvin to Celsius
Expand Down Expand Up @@ -228,6 +230,7 @@ def K2C(K):
"""
return _np.asanyarray(K) - zero_Celsius


def F2C(F):
"""
Convert Fahrenheit to Celsius
Expand Down Expand Up @@ -255,6 +258,7 @@ def F2C(F):
"""
return (_np.asanyarray(F) - 32) / 1.8


def C2F(C):
"""
Convert Celsius to Fahrenheit
Expand Down Expand Up @@ -282,6 +286,7 @@ def C2F(C):
"""
return 1.8 * _np.asanyarray(C) + 32


def F2K(F):
"""
Convert Fahrenheit to Kelvin
Expand Down Expand Up @@ -311,6 +316,7 @@ def F2K(F):
"""
return C2K(F2C(_np.asanyarray(F)))


def K2F(K):
"""
Convert Kelvin to Fahrenheit
Expand Down Expand Up @@ -342,6 +348,7 @@ def K2F(K):

#optics


def lambda2nu(lambda_):
"""
Convert wavelength to optical frequency
Expand Down Expand Up @@ -370,6 +377,7 @@ def lambda2nu(lambda_):
"""
return _np.asanyarray(c) / lambda_


def nu2lambda(nu):
"""
Convert optical frequency to wavelength.
Expand Down
5 changes: 5 additions & 0 deletions scipy/constants/tests/test_codata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,26 @@ def test_basic_table_parse():
assert_equal(codata.value(c), constants.c)
assert_equal(codata.value(c), constants.speed_of_light)


def test_basic_lookup():
assert_equal('%d %s' % (codata.c, codata.unit('speed of light in vacuum')),
'299792458 m s^-1')


def test_find_all():
assert_(len(codata.find(disp=False)) > 300)


def test_find_single():
assert_equal(codata.find('Wien freq', disp=False)[0],
'Wien frequency displacement law constant')


def test_2002_vs_2006():
assert_almost_equal(codata.value('magn. flux quantum'),
codata.value('mag. flux quantum'))


def test_exact_values():
"""Check that updating stored values with exact ones worked."""
for key in codata.exact_values:
Expand Down
Loading

0 comments on commit 5d565c0

Please sign in to comment.