Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of 2to3 #397

Merged
merged 43 commits into from Jan 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3add620
MAINT: Automated 2to3 conversion of the code base
pv Jan 5, 2013
74e42cf
BLD: Remove 2to3 conversion step from the build
pv Jan 5, 2013
410f27e
ENH: lib: bundle six Python 2/3 compatibility module
pv Jan 5, 2013
8765151
PY23: tools: single-sourcify authors.py
pv Jan 5, 2013
57410d5
PY23: special: remove unnecessary list()'s + remove unused file
pv Jan 5, 2013
af33e9a
PY23: cluster: remove unnecessary list()'s
pv Jan 5, 2013
e730a5a
PY23: cluster: fix string type handling
pv Jan 5, 2013
3d89473
PY23: constants: remove unnecessary list()'s
pv Jan 5, 2013
e211e2c
PY23: fftpack: print -> print_
pv Jan 5, 2013
e965867
PY23: integrate: print -> print_
pv Jan 5, 2013
5131c12
PY23: interpolate/rbf: fix function code handling + callable()
pv Jan 5, 2013
b220321
PY23: interpolate: remove unnecessary list()'s + minor cleanup
pv Jan 5, 2013
4c1497e
PY23: io: remove unnecessary list()'s
pv Jan 5, 2013
7a9ff05
PY23: io/arff: import next() on Py2
pv Jan 5, 2013
71a88fc
PY23: io: fix string handling + add some missing imports + fix int ty…
pv Jan 5, 2013
68362ad
PY23: lib: port decorator.py
pv Jan 5, 2013
c6298be
PY23: linalg: callable()
pv Jan 5, 2013
16bfcf9
PY23: linalg: print -> print_
pv Jan 5, 2013
1fc7594
PY23: linalg: remove unnecessary list()'s + minor fixes
pv Jan 5, 2013
cacf46d
PY23: misc: remove unnecessary list()'s
pv Jan 5, 2013
a01536a
PY23: ndimage: fix type handling
pv Jan 5, 2013
6ad855d
PY23: ndimage: remove unnecessary list()'s + minor fixes
pv Jan 5, 2013
155cd94
PY23: odr: print -> print_ + remove unnecessary list()'s
pv Jan 5, 2013
c1cbb7d
PY23: optimize: callable() + exec + builtins
pv Jan 5, 2013
787b8d0
PY23: optimize: remove unnecessary list()'s
pv Jan 5, 2013
2f14a14
PY23: optimize: print -> print_
pv Jan 5, 2013
f8190b2
PY23: signal: callable() + remove unnecessary list()'s
pv Jan 5, 2013
86b09ae
PY23: linalg: print -> print_
pv Jan 5, 2013
1e18856
PY23: sparse.linalg: iteritems + remove unnecessary list()'s + other …
pv Jan 5, 2013
dbe3310
PY23: sparse: __bool__/__nonzero__ + remove unnecessary list()'s + it…
pv Jan 5, 2013
d44cccc
PY23: spatial: print -> print_
pv Jan 5, 2013
adf9d24
PY23: spatial: callable + unicode literals + string type handling
pv Jan 5, 2013
a2af3a1
PY23: spatial: remove unnecessary list()'s
pv Jan 5, 2013
d413935
PY23: stats: remove unnecessary list()'s
pv Jan 5, 2013
387a5c3
PY23: stats: iteritems
pv Jan 5, 2013
6cae894
PY23: stats: string type handling + callable + method function + func…
pv Jan 5, 2013
3b9859f
PY23: restore xrange()
pv Jan 5, 2013
9eab150
TST: interpolate: fix list comprehension Py2/3 scope difference intro…
pv Jan 5, 2013
61b8136
PY23: signal: convert spectral.py
pv Jan 5, 2013
ce73f19
MAINT: replace asbytes(literal) by bytes literals
pv Jan 5, 2013
29ff5a6
MAINT: use __future__.print_function instead of six.print_
pv Jan 6, 2013
5f4c579
MAINT: add relevant from __future__ import to all files
pv Jan 6, 2013
c57d14d
TST: io/harwell_boeing: use StringIO.StringIO on Python 2 to stay wit…
pv Jan 6, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions scipy/__init__.py
Expand Up @@ -58,6 +58,7 @@
__numpy_version__ --- Numpy version string

"""
from __future__ import division, print_function, absolute_import

__all__ = ['test']

Expand Down
3 changes: 2 additions & 1 deletion scipy/cluster/__init__.py
Expand Up @@ -20,10 +20,11 @@
to generate flat clusters, and visualizing clusters with dendrograms.

"""
from __future__ import division, print_function, absolute_import

__all__ = ['vq', 'hierarchy']

import vq, hierarchy
from . import vq, hierarchy

from numpy.testing import Tester
test = Tester().test
6 changes: 4 additions & 2 deletions scipy/cluster/doc/ex1.py
@@ -1,3 +1,5 @@
from __future__ import division, print_function, absolute_import

from scipy import *
from scipy.cluster import vq

Expand Down Expand Up @@ -33,5 +35,5 @@ def cluster_data(data,cluster_cnt,iter=20,thresh=1e-5):

clusters = cluster_data(data,2)
for i in range(len(clusters)):
print 'cluster %d:' % i
print clusters[i]
print('cluster %d:' % i)
print(clusters[i])
33 changes: 18 additions & 15 deletions scipy/cluster/hierarchy.py
Expand Up @@ -130,6 +130,7 @@
* Mathematica is a registered trademark of The Wolfram Research, Inc.

"""
from __future__ import division, print_function, absolute_import

# Copyright (C) Damian Eads, 2007-2008. New BSD License.

Expand Down Expand Up @@ -172,9 +173,11 @@
import warnings

import numpy as np
import _hierarchy_wrap
from . import _hierarchy_wrap
import scipy.spatial.distance as distance

from scipy.lib.six import string_types
from scipy.lib.six.moves import xrange

_cpy_non_euclid_methods = {'single': 0, 'complete': 1, 'average': 2,
'weighted': 6}
Expand Down Expand Up @@ -1231,7 +1234,7 @@ def is_valid_im(R, warning=False, throw=False, name=None):
else:
raise ValueError('Inconsistency matrix contains negative '
'link counts.')
except Exception, e:
except Exception as e:
if throw:
raise
if warning:
Expand Down Expand Up @@ -1345,7 +1348,7 @@ def is_valid_linkage(Z, warning=False, throw=False, name=None):
# % name)
# else:
# raise ValueError('Linkage does not use all clusters.')
except Exception, e:
except Exception as e:
if throw:
raise
if warning:
Expand Down Expand Up @@ -1811,7 +1814,7 @@ def _plot_dendrogram(icoords, dcoords, ivl, p, n, mh, orientation,
for color in colors_used:
color_to_lines[color] = []
for (xline, yline, color) in zip(xlines, ylines, color_list):
color_to_lines[color].append(zip(xline, yline))
color_to_lines[color].append(list(zip(xline, yline)))

colors_to_collections = {}
# Construct the collections.
Expand Down Expand Up @@ -1874,9 +1877,9 @@ def set_link_color_palette(palette):

"""

if type(palette) not in (types.ListType, types.TupleType):
if type(palette) not in (list, tuple):
raise TypeError("palette must be a list or tuple")
_ptypes = [type(p) == types.StringType for p in palette]
_ptypes = [isinstance(p, string_types) for p in palette]

if False in _ptypes:
raise TypeError("all palette list elements must be color strings")
Expand Down Expand Up @@ -2088,7 +2091,7 @@ def llf(id):
is_valid_linkage(Z, throw=True, name='Z')
Zs = Z.shape
n = Zs[0] + 1
if type(p) in (types.IntType, types.FloatType):
if type(p) in (int, float):
p = int(p)
else:
raise TypeError('The second argument must be a number')
Expand Down Expand Up @@ -2117,7 +2120,7 @@ def llf(id):
else:
ivl = []
if color_threshold is None or \
(type(color_threshold) == types.StringType and
(isinstance(color_threshold, string_types) and
color_threshold == 'default'):
color_threshold = max(Z[:, 2]) * 0.7
R = {'icoord': icoord_list, 'dcoord': dcoord_list, 'ivl': ivl,
Expand Down Expand Up @@ -2454,7 +2457,7 @@ def _dendrogram_calculate_info(Z, p, truncate_mode, \
dcoord_list.append([uah, h, h, ubh])
if link_color_func is not None:
v = link_color_func(int(i))
if type(v) != types.StringType:
if not isinstance(v, string_types):
raise TypeError("link_color_func must return a matplotlib "
"color string!")
color_list.append(v)
Expand Down Expand Up @@ -2501,7 +2504,7 @@ def is_isomorphic(T1, T2):
n = T1S[0]
d = {}
for i in xrange(0, n):
if T1[i] in d.keys():
if T1[i] in list(d.keys()):
if d[T1[i]] != T2[i]:
return False
else:
Expand Down Expand Up @@ -2602,7 +2605,7 @@ def maxRstat(Z, R, i):
R = np.asarray(R, order='c')
is_valid_linkage(Z, throw=True, name='Z')
is_valid_im(R, throw=True, name='R')
if type(i) is not types.IntType:
if type(i) is not int:
raise TypeError('The third argument must be an integer.')
if i < 0 or i > 3:
raise ValueError('i must be an integer between 0 and 3 inclusive.')
Expand Down Expand Up @@ -2711,13 +2714,13 @@ def _leader_identify(tr, T):
right = tr.get_right()
lfid = _leader_identify(left, T)
rfid = _leader_identify(right, T)
print 'ndid: %d lid: %d lfid: %d rid: %d rfid: %d' \
% (tr.get_id(), left.get_id(), lfid, right.get_id(), rfid)
print('ndid: %d lid: %d lfid: %d rid: %d rfid: %d' \
% (tr.get_id(), left.get_id(), lfid, right.get_id(), rfid))
if lfid != rfid:
if lfid != -1:
print 'leader: %d with tag %d' % (left.id, lfid)
print('leader: %d with tag %d' % (left.id, lfid))
if rfid != -1:
print 'leader: %d with tag %d' % (right.id, rfid)
print('leader: %d with tag %d' % (right.id, rfid))
return -1
else:
return lfid
Expand Down
2 changes: 2 additions & 0 deletions scipy/cluster/setup.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python
from __future__ import division, print_function, absolute_import

import sys

from os.path import join
Expand Down
1 change: 1 addition & 0 deletions scipy/cluster/setupscons.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import division, print_function, absolute_import

from os.path import join

Expand Down
7 changes: 5 additions & 2 deletions scipy/cluster/tests/test_hierarchy.py
Expand Up @@ -32,12 +32,15 @@
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import division, print_function, absolute_import

import os.path

import numpy as np
from numpy.testing import TestCase, run_module_suite

from scipy.lib.six.moves import xrange

from scipy.cluster.hierarchy import linkage, from_mlab_linkage, to_mlab_linkage,\
num_obs_linkage, inconsistent, cophenet, fclusterdata, fcluster, \
is_isomorphic, single, complete, weighted, centroid, leaders, \
Expand Down Expand Up @@ -790,7 +793,7 @@ def test_correspond_2_and_up(self):

def test_correspond_4_and_up(self):
"Tests correspond(Z, y) on linkage and CDMs over observation sets of different sizes. Correspondance should be false."
for (i, j) in zip(range(2, 4), range(3, 5)) + zip(range(3, 5), range(2, 4)):
for (i, j) in list(zip(list(range(2, 4)), list(range(3, 5)))) + list(zip(list(range(3, 5)), list(range(2, 4)))):
y = np.random.rand(i*(i-1)/2)
y2 = np.random.rand(j*(j-1)/2)
Z = linkage(y)
Expand All @@ -800,7 +803,7 @@ def test_correspond_4_and_up(self):

def test_correspond_4_and_up_2(self):
"Tests correspond(Z, y) on linkage and CDMs over observation sets of different sizes. Correspondance should be false."
for (i, j) in zip(range(2, 7), range(16, 21)) + zip(range(2, 7), range(16, 21)):
for (i, j) in list(zip(list(range(2, 7)), list(range(16, 21)))) + list(zip(list(range(2, 7)), list(range(16, 21)))):
y = np.random.rand(i*(i-1)/2)
y2 = np.random.rand(j*(j-1)/2)
Z = linkage(y)
Expand Down
7 changes: 4 additions & 3 deletions scipy/cluster/tests/test_vq.py
Expand Up @@ -2,6 +2,7 @@

# David Cournapeau
# Last Change: Wed Nov 05 07:00 PM 2008 J
from __future__ import division, print_function, absolute_import

import os.path
import warnings
Expand All @@ -16,7 +17,7 @@
from scipy.cluster import _vq
TESTC=True
except ImportError:
print "== Error while importing _vq, not testing C imp of vq =="
print("== Error while importing _vq, not testing C imp of vq ==")
TESTC=False

#Optional:
Expand Down Expand Up @@ -59,7 +60,7 @@ def test_vq(self):
assert_array_equal(label1, LABEL1)
tlabel1, tdist = vq(X, initc)
else:
print "== not testing C imp of vq =="
print("== not testing C imp of vq ==")

#def test_py_vq_1d(self):
# """Test special rank 1 vq algo, python implementation."""
Expand All @@ -82,7 +83,7 @@ def test_vq_1d(self):
assert_array_equal(a, ta)
assert_array_equal(b, tb)
else:
print "== not testing C imp of vq (rank 1) =="
print("== not testing C imp of vq (rank 1) ==")

def test__vq_sametype(self):
if TESTC:
Expand Down
4 changes: 3 additions & 1 deletion scipy/cluster/tests/vq_test.py
@@ -1,3 +1,5 @@
from __future__ import division, print_function, absolute_import

import numpy as np
from scipy.cluster import vq

Expand Down Expand Up @@ -28,7 +30,7 @@ def read_data(name):
f = open(name,'r')
data = []
for line in f.readlines():
data.append(map(float,string.split(line)))
data.append(list(map(float,string.split(line))))
f.close()
return array(data)

Expand Down
6 changes: 4 additions & 2 deletions scipy/cluster/vq.py
Expand Up @@ -67,6 +67,8 @@
code book.

"""
from __future__ import division, print_function, absolute_import

__docformat__ = 'restructuredtext'

__all__ = ['whiten', 'vq', 'kmeans', 'kmeans2']
Expand Down Expand Up @@ -188,7 +190,7 @@ def vq(obs, code_book):

"""
try:
import _vq
from . import _vq
ct = common_type(obs, code_book)
c_obs = obs.astype(ct)
c_code_book = code_book.astype(ct)
Expand Down Expand Up @@ -289,7 +291,7 @@ def _py_vq_1d(obs, code_book):
dist = np.zeros((n, nc))
for i in range(nc):
dist[:, i] = np.sum(obs - code_book[i])
print dist
print(dist)
code = argmin(dist)
min_dist = dist[code]

Expand Down
9 changes: 5 additions & 4 deletions scipy/constants/__init__.py
Expand Up @@ -282,11 +282,12 @@
http://physics.nist.gov/cuu/Constants/index.html

"""
from __future__ import division, print_function, absolute_import

# Modules contributed by BasSw (wegwerp@gmail.com)
from codata import *
from constants import *
from codata import _obsolete_constants
from .codata import *
from .constants import *
from .codata import _obsolete_constants

_constant_names = [(_k.lower(), _k, _v)
for _k, _v in physical_constants.items()
Expand All @@ -297,6 +298,6 @@
__doc__ = __doc__ % dict(constant_names=_constant_names)
del _constant_names

__all__ = filter(lambda s:not s.startswith('_'),dir())
__all__ = [s for s in dir() if not s.startswith('_')]
from numpy.testing import Tester
test = Tester().test
12 changes: 7 additions & 5 deletions scipy/constants/codata.py
Expand Up @@ -21,6 +21,8 @@
http://physics.nist.gov/cuu/Constants/

"""
from __future__ import division, print_function, absolute_import


import warnings
from math import pi, sqrt
Expand Down Expand Up @@ -801,16 +803,16 @@ def parse_constants(d):

# check obsolete values
_obsolete_constants = {}
for k in physical_constants.iterkeys():
for k in physical_constants.keys():
if k not in _current_constants:
_obsolete_constants[k] = True

# generate some additional aliases
_aliases = {}
for k in _physical_constants_2002.iterkeys():
for k in _physical_constants_2002.keys():
if 'magn.' in k:
_aliases[k] = k.replace('magn.', 'mag.')
for k in _physical_constants_2006.iterkeys():
for k in _physical_constants_2006.keys():
if 'momentum' in k:
_aliases[k] = k.replace('momentum', 'mom.um')

Expand Down Expand Up @@ -935,15 +937,15 @@ def find(sub=None, disp=False):

"""
if sub is None:
result = _current_constants.keys()
result = list(_current_constants.keys())
else:
result = [key for key in _current_constants \
if sub.lower() in key.lower()]

result.sort()
if disp:
for key in result:
print key
print(key)
return
else:
return result
Expand Down
3 changes: 2 additions & 1 deletion scipy/constants/constants.py
Expand Up @@ -6,6 +6,7 @@

The list is not meant to be comprehensive, but just a convenient list for everyday use.
"""
from __future__ import division, print_function, absolute_import

"""
BasSw 2006
Expand All @@ -17,7 +18,7 @@
"""

import math as _math
from codata import value as _cd
from .codata import value as _cd
import numpy as _np

#mathematical constants
Expand Down
1 change: 1 addition & 0 deletions scipy/constants/setup.py
@@ -1,3 +1,4 @@
from __future__ import division, print_function, absolute_import


def configuration(parent_package='', top_path=None):
Expand Down
2 changes: 2 additions & 0 deletions scipy/constants/tests/test_codata.py
@@ -1,3 +1,5 @@
from __future__ import division, print_function, absolute_import

import warnings

from scipy.constants import constants, codata, find, value
Expand Down
2 changes: 2 additions & 0 deletions scipy/constants/tests/test_constants.py
@@ -1,3 +1,5 @@
from __future__ import division, print_function, absolute_import

from numpy.testing import run_module_suite, assert_equal
import scipy.constants as sc

Expand Down