Skip to content

Commit

Permalink
REF remove 2to3
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgoodman committed Oct 28, 2013
1 parent 1036171 commit 3c342d2
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 39 deletions.
18 changes: 9 additions & 9 deletions la/deflarry.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self, x, label=None, dtype=None, validate=True):
count = {} count = {}
for li in l: for li in l:
count[li] = count.get(li, 0) + 1 count[li] = count.get(li, 0) + 1
for key, value in count.iteritems(): for key, value in count.items():
if value > 1: if value > 1:
break break
msg = "Elements of label not unique along axis %d. " msg = "Elements of label not unique along axis %d. "
Expand Down Expand Up @@ -2695,9 +2695,9 @@ def maplabel(self, func, axis=None, copy=True):
y = self y = self
if axis is None: if axis is None:
for ax in range(y.ndim): for ax in range(y.ndim):
y.label[ax] = map(func, y.label[ax]) y.label[ax] = list(map(func, y.label[ax]))
else: else:
y.label[axis] = map(func, y.label[axis]) y.label[axis] = list(map(func, y.label[axis]))
return y return y


# Moving window statistics ---------------------------------------------- # Moving window statistics ----------------------------------------------
Expand Down Expand Up @@ -4480,9 +4480,9 @@ def totuples(self):
""" """
yf = self.flatten() yf = self.flatten()
z = zip(*yf.label[0]) z = list(zip(*yf.label[0]))
z.append(yf.x.tolist()) z.append(yf.x.tolist())
return zip(*z) return list(zip(*z))


@staticmethod @staticmethod
def fromtuples(data): def fromtuples(data):
Expand Down Expand Up @@ -4551,7 +4551,7 @@ def fromtuples(data):
return larry([]) return larry([])
else: else:
# Split data into label and x # Split data into label and x
labels = zip(*data) labels = list(zip(*data))
xs = labels.pop(-1) xs = labels.pop(-1)
# Determine labels, shape, and index into array # Determine labels, shape, and index into array
x, label = fromlists(xs, labels) x, label = fromlists(xs, labels)
Expand Down Expand Up @@ -4629,7 +4629,7 @@ def fromlist(data):
if len(data) == 0: if len(data) == 0:
return larry([]) return larry([])
else: else:
x, label = fromlists(data[0], zip(*data[1])) x, label = fromlists(data[0], list(zip(*data[1])))
return larry(x, label) return larry(x, label)


def todict(self): def todict(self):
Expand Down Expand Up @@ -4699,7 +4699,7 @@ def fromdict(data):
[ 3., 4.]]) [ 3., 4.]])
""" """
return larry.fromlist([data.values(), data.keys()]) return larry.fromlist([list(data.values()), list(data.keys())])


def tocsv(self, filename, delimiter=','): def tocsv(self, filename, delimiter=','):
""" """
Expand Down Expand Up @@ -5166,7 +5166,7 @@ def slicemaker(index, labelindex, axis):
def labels2indices(label, labels): def labels2indices(label, labels):
"Convert list of labels to indices" "Convert list of labels to indices"
try: try:
indices = map(label.index, labels) indices = list(map(label.index, labels))
except ValueError: except ValueError:
raise ValueError('Could not map label to index value.') raise ValueError('Could not map label to index value.')
return indices return indices
7 changes: 0 additions & 7 deletions la/flabel.py
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,5 @@
"label (list of lists) functions" "label (list of lists) functions"


try:
import itertools.izip as zip
except ImportError: # Python 3
pass

import numpy as np

try: try:
# The c version is faster... # The c version is faster...
from la.cflabel import listmap from la.cflabel import listmap
Expand Down
12 changes: 6 additions & 6 deletions la/io.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@ def _load_label(group, ndim):
labellist = g[:].tolist() labellist = g[:].tolist()
datetime_type = group[str(i)].attrs['datetime_type'] datetime_type = group[str(i)].attrs['datetime_type']
if datetime_type == 'date': if datetime_type == 'date':
labellist = map(datetime.date.fromordinal, labellist) labellist = list(map(datetime.date.fromordinal, labellist))
elif datetime_type == 'time': elif datetime_type == 'time':
labellist = map(tuple2time, labellist) labellist = list(map(tuple2time, labellist))
elif datetime_type == 'datetime': elif datetime_type == 'datetime':
labellist = map(tuple2datetime, labellist) labellist = list(map(tuple2datetime, labellist))
label.append(labellist) label.append(labellist)
return label return label


Expand All @@ -658,14 +658,14 @@ def _list2array(x):
msg += 'same type.' msg += 'same type.'
raise TypeError(msg) raise TypeError(msg)
if type0 == datetime.date: if type0 == datetime.date:
x = map(datetime.date.toordinal, x) x = list(map(datetime.date.toordinal, x))
datetime_type = 'date' datetime_type = 'date'
elif type0 == datetime.time: elif type0 == datetime.time:
x = map(time2tuple, x) x = list(map(time2tuple, x))
datetime_type = 'time' datetime_type = 'time'
dtype = "i4,i4,i4,i4" dtype = "i4,i4,i4,i4"
elif type0 == datetime.datetime: elif type0 == datetime.datetime:
x = map(datetime2tuple, x) x = list(map(datetime2tuple, x))
datetime_type = 'datetime' datetime_type = 'datetime'
dtype = ','.join(["i4" for i in range(len(x[0]))]) dtype = ','.join(["i4" for i in range(len(x[0]))])
return np.asarray(x, dtype=dtype), datetime_type return np.asarray(x, dtype=dtype), datetime_type
Expand Down
2 changes: 1 addition & 1 deletion la/tests/all_nan_test.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def functions():
def test_all_nan(): def test_all_nan():
"Test larry methods for proper handling of all NaN input" "Test larry methods for proper handling of all NaN input"
err_msg = "%s did not return NaN" err_msg = "%s did not return NaN"
for parameters, methods in functions().iteritems(): for parameters, methods in functions().items():
for method in methods: for method in methods:
with np.errstate(invalid='ignore', divide='ignore'): with np.errstate(invalid='ignore', divide='ignore'):
actual = getattr(lar(), method)(*parameters) actual = getattr(lar(), method)(*parameters)
Expand Down
6 changes: 5 additions & 1 deletion la/tests/deflarry_nose_test.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# For support of python 2.5 # For support of python 2.5
from __future__ import with_statement from __future__ import with_statement


try:
from cStringIO import StringIO
except ImportError: # Python 3
from io import StringIO

from copy import deepcopy from copy import deepcopy
from StringIO import StringIO


import numpy as np import numpy as np
nan = np.nan nan = np.nan
Expand Down
2 changes: 1 addition & 1 deletion la/tests/deflarry_test.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3538,7 +3538,7 @@ def take_test():
y = la.rand(*shape) y = la.rand(*shape)
for axis in range(y.ndim): for axis in range(y.ndim):
for i in range(1, y.shape[axis]): for i in range(1, y.shape[axis]):
idx = range(i)[::-1] idx = list(range(i))[::-1]
ytake = y.take(idx, axis=axis) ytake = y.take(idx, axis=axis)
index = [slice(None)] * y.ndim index = [slice(None)] * y.ndim
index[axis] = idx index[axis] = idx
Expand Down
2 changes: 1 addition & 1 deletion la/tests/empty_larry_test.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_reduce_shape():
msg = 'larry.%s failed for shape %s and axis %s' msg = 'larry.%s failed for shape %s and axis %s'
for method in reduce_methods(): for method in reduce_methods():
for shape in get_shapes(): for shape in get_shapes():
axeslist = [None] + range(len(shape)) axeslist = [None] + list(range(len(shape)))
for axis in axeslist: for axis in axeslist:
arr = np.zeros(shape) arr = np.zeros(shape)
npmethod = getattr(arr, method['np']) npmethod = getattr(arr, method['np'])
Expand Down
6 changes: 3 additions & 3 deletions la/tests/flabel_test.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def listmap_test():
msg = "listmap failed on list1=%s and list2=%s and ignore_unmappable=%s" msg = "listmap failed on list1=%s and list2=%s and ignore_unmappable=%s"
for i in range(100): for i in range(100):
np.random.shuffle(list2) np.random.shuffle(list2)
idx1 = map(list1.index, list2) idx1 = list(map(list1.index, list2))
idx2 = listmap(list1, list2) idx2 = listmap(list1, list2)
ignore_unmappable = False ignore_unmappable = False
yield assert_equal, idx1, idx2, msg % (list1, list2, ignore_unmappable) yield assert_equal, idx1, idx2, msg % (list1, list2, ignore_unmappable)
Expand All @@ -34,7 +34,7 @@ def listmap_unmappable_test():
list1 = list(range(6)) list1 = list(range(6))
list2 = list(range(5)) list2 = list(range(5))
np.random.shuffle(list2) np.random.shuffle(list2)
idx1 = map(list1.index, list2) idx1 = list(map(list1.index, list2))
list2 = ['unmappable #1'] + list2 + ['unmappable #2'] list2 = ['unmappable #1'] + list2 + ['unmappable #2']
ignore_unmappable = True ignore_unmappable = True
idx2 = listmap(list1, list2, ignore_unmappable=ignore_unmappable) idx2 = listmap(list1, list2, ignore_unmappable=ignore_unmappable)
Expand All @@ -56,7 +56,7 @@ def listmap_fill_test():
msg = "listmap_fill failed on list1=%s and list2=%s" msg = "listmap_fill failed on list1=%s and list2=%s"
for i in range(100): for i in range(100):
np.random.shuffle(list2) np.random.shuffle(list2)
idx1 = map(list1.index, list2) idx1 = list(map(list1.index, list2))
idx2, ignore = listmap_fill(list1, list2) idx2, ignore = listmap_fill(list1, list2)
yield assert_equal, idx1, idx2, msg % (list1, list2) yield assert_equal, idx1, idx2, msg % (list1, list2)


Expand Down
1 change: 0 additions & 1 deletion la/util/misc.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -210,4 +210,3 @@ def fromlists(xs, labels):
x.fill(np.nan) x.fill(np.nan)
x[index] = xs x[index] = xs
return x, label return x, label

2 changes: 1 addition & 1 deletion la/util/resample.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def cross_validation(n, kfold, shuffle=None):
raise ValueError("`kfold` must be two or greater.") raise ValueError("`kfold` must be two or greater.")
if kfold > n: if kfold > n:
raise ValueError("`kfold` cannot be greater than `n`") raise ValueError("`kfold` cannot be greater than `n`")
index = range(n) index = list(range(n))
if shuffle is None: if shuffle is None:
np.random.shuffle(index) np.random.shuffle(index)
else: else:
Expand Down
2 changes: 1 addition & 1 deletion la/util/tests/misc_test.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_isa():
t[(np.array(1)[()], 6)] = (True, False) t[(np.array(1)[()], 6)] = (True, False)
t[(np.array(1.1)[()], 7)] = (False, True) t[(np.array(1.1)[()], 7)] = (False, True)
t[(1j, 8)] = (False, False) t[(1j, 8)] = (False, False)
for key, value in t.iteritems(): for key, value in t.items():
key = key[0] key = key[0]
msg = '\nisint(' + str(key) + ')' msg = '\nisint(' + str(key) + ')'
yield assert_equal, isint(key), value[0], msg yield assert_equal, isint(key), value[0], msg
Expand Down
7 changes: 0 additions & 7 deletions setup.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
from distutils.core import setup from distutils.core import setup
from distutils.extension import Extension from distutils.extension import Extension


try:
from distutils.command.build_py import build_py_2to3 as build_py
except ImportError:
from distutils.command.build_py import build_py

CLASSIFIERS = ["Development Status :: 4 - Beta", CLASSIFIERS = ["Development Status :: 4 - Beta",
"Environment :: Console", "Environment :: Console",
"Intended Audience :: Science/Research", "Intended Audience :: Science/Research",
Expand Down Expand Up @@ -79,7 +74,6 @@
package_data=PACKAGE_DATA, package_data=PACKAGE_DATA,
requires=REQUIRES, requires=REQUIRES,
ext_modules = [Extension("la.cflabel", ["la/src/cflabel.c"])], ext_modules = [Extension("la.cflabel", ["la/src/cflabel.c"])],
cmdclass={'build_py': build_py}
) )
except SystemExit: except SystemExit:
# Probably clistmap.c failed to compile, so use slower python version # Probably clistmap.c failed to compile, so use slower python version
Expand All @@ -102,5 +96,4 @@
packages=PACKAGES, packages=PACKAGES,
package_data=PACKAGE_DATA, package_data=PACKAGE_DATA,
requires=REQUIRES, requires=REQUIRES,
cmdclass={'build_py': build_py}
) )

0 comments on commit 3c342d2

Please sign in to comment.