Skip to content

Commit 8ac0e11

Browse files
committed
Merge pull request #4384 from jtratner/better-python3-compat
CLN/ENH/BLD: Remove need for 2to3 for Python 3.
2 parents 7e896ea + fa16b95 commit 8ac0e11

File tree

198 files changed

+3667
-3150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+3667
-3150
lines changed

LICENSES/SIX

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
six license (substantial portions used in the python 3 compatibility module)
2+
===========================================================================
3+
Copyright (c) 2010-2013 Benjamin Peterson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
#
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
#
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

bench/alignment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Setup
2+
from pandas.compat import range, lrange
23
import numpy as np
34
import pandas
45
import la
56
N = 1000
67
K = 50
78
arr1 = np.random.randn(N, K)
89
arr2 = np.random.randn(N, K)
9-
idx1 = range(N)
10-
idx2 = range(K)
10+
idx1 = lrange(N)
11+
idx2 = lrange(K)
1112

1213
# pandas
1314
dma1 = pandas.DataFrame(arr1, idx1, idx2)

bench/bench_get_put_value.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from pandas import *
22
from pandas.util.testing import rands
3+
from pandas.compat import range
34

45
N = 1000
56
K = 50
67

78

89
def _random_index(howmany):
9-
return Index([rands(10) for _ in xrange(howmany)])
10+
return Index([rands(10) for _ in range(howmany)])
1011

1112
df = DataFrame(np.random.randn(N, K), index=_random_index(N),
1213
columns=_random_index(K))

bench/bench_groupby.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from pandas import *
22
from pandas.util.testing import rands
3+
from pandas.compat import range
34

45
import string
56
import random
67

78
k = 20000
89
n = 10
910

10-
foo = np.tile(np.array([rands(10) for _ in xrange(k)], dtype='O'), n)
11+
foo = np.tile(np.array([rands(10) for _ in range(k)], dtype='O'), n)
1112
foo2 = list(foo)
1213
random.shuffle(foo)
1314
random.shuffle(foo2)

bench/bench_join_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def reindex_on_axis(panels, axis, axis_reindex):
3535
# concatenate values
3636
try:
3737
values = np.concatenate([p.values for p in panels], axis=1)
38-
except (Exception), detail:
38+
except Exception as detail:
3939
raise Exception("cannot append values that dont' match dimensions! -> [%s] %s"
4040
% (','.join(["%s" % p for p in panels]), str(detail)))
4141
# pm('append - create_panel')

bench/bench_khash_dict.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""
22
Some comparisons of khash.h to Python dict
33
"""
4+
from __future__ import print_function
45

56
import numpy as np
67
import os
78

89
from vbench.api import Benchmark
910
from pandas.util.testing import rands
11+
from pandas.compat import range
1012
import pandas._tseries as lib
1113
import pandas._sandbox as sbx
1214
import time
@@ -22,7 +24,7 @@ def object_test_data(n):
2224

2325

2426
def string_test_data(n):
25-
return np.array([rands(10) for _ in xrange(n)], dtype='O')
27+
return np.array([rands(10) for _ in range(n)], dtype='O')
2628

2729

2830
def int_test_data(n):
@@ -50,7 +52,7 @@ def f():
5052

5153
def _timeit(f, iterations=10):
5254
start = time.time()
53-
for _ in xrange(iterations):
55+
for _ in range(iterations):
5456
foo = f()
5557
elapsed = time.time() - start
5658
return elapsed
@@ -73,8 +75,8 @@ def lookup_khash(values):
7375

7476

7577
def leak(values):
76-
for _ in xrange(100):
77-
print proc.get_memory_info()
78+
for _ in range(100):
79+
print(proc.get_memory_info())
7880
table = lookup_khash(values)
7981
# table.destroy()
8082

bench/bench_merge.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import random
2+
import gc
3+
import time
14
from pandas import *
5+
from pandas.compat import range, lrange, StringIO
26
from pandas.util.testing import rands
3-
import random
47

58
N = 10000
69
ngroups = 10
710

811

912
def get_test_data(ngroups=100, n=N):
10-
unique_groups = range(ngroups)
13+
unique_groups = lrange(ngroups)
1114
arr = np.asarray(np.tile(unique_groups, n / ngroups), dtype=object)
1215

1316
if len(arr) < n:
@@ -28,14 +31,10 @@ def get_test_data(ngroups=100, n=N):
2831
# 'value' : np.random.randn(N // 10)})
2932
# result = merge.merge(df, df2, on='key2')
3033

31-
from collections import defaultdict
32-
import gc
33-
import time
34-
from pandas.util.testing import rands
3534
N = 10000
3635

37-
indices = np.array([rands(10) for _ in xrange(N)], dtype='O')
38-
indices2 = np.array([rands(10) for _ in xrange(N)], dtype='O')
36+
indices = np.array([rands(10) for _ in range(N)], dtype='O')
37+
indices2 = np.array([rands(10) for _ in range(N)], dtype='O')
3938
key = np.tile(indices[:8000], 10)
4039
key2 = np.tile(indices2[:8000], 10)
4140

@@ -55,7 +54,7 @@ def get_test_data(ngroups=100, n=N):
5554
f = lambda: merge(left, right, how=join_method, sort=sort)
5655
gc.disable()
5756
start = time.time()
58-
for _ in xrange(niter):
57+
for _ in range(niter):
5958
f()
6059
elapsed = (time.time() - start) / niter
6160
gc.enable()
@@ -65,7 +64,6 @@ def get_test_data(ngroups=100, n=N):
6564

6665

6766
# R results
68-
from StringIO import StringIO
6967
# many to one
7068
r_results = read_table(StringIO(""" base::merge plyr data.table
7169
inner 0.2475 0.1183 0.1100
@@ -93,7 +91,6 @@ def get_test_data(ngroups=100, n=N):
9391

9492
# many to many
9593

96-
from StringIO import StringIO
9794
# many to one
9895
r_results = read_table(StringIO("""base::merge plyr data.table
9996
inner 0.4610 0.1276 0.1269

bench/bench_merge_sqlite.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import time
55
from pandas import DataFrame
66
from pandas.util.testing import rands
7+
from pandas.compat import range, zip
78
import random
89

910
N = 10000
1011

11-
indices = np.array([rands(10) for _ in xrange(N)], dtype='O')
12-
indices2 = np.array([rands(10) for _ in xrange(N)], dtype='O')
12+
indices = np.array([rands(10) for _ in range(N)], dtype='O')
13+
indices2 = np.array([rands(10) for _ in range(N)], dtype='O')
1314
key = np.tile(indices[:8000], 10)
1415
key2 = np.tile(indices2[:8000], 10)
1516

@@ -67,7 +68,7 @@
6768
g = lambda: conn.execute(sql) # list fetches results
6869
gc.disable()
6970
start = time.time()
70-
# for _ in xrange(niter):
71+
# for _ in range(niter):
7172
g()
7273
elapsed = (time.time() - start) / niter
7374
gc.enable()

bench/bench_sparse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from pandas import *
55
import pandas.core.sparse as spm
6+
import pandas.compat as compat
67
reload(spm)
78
from pandas.core.sparse import *
89

@@ -41,7 +42,7 @@
4142

4243
def new_data_like(sdf):
4344
new_data = {}
44-
for col, series in sdf.iteritems():
45+
for col, series in compat.iteritems(sdf):
4546
new_data[col] = SparseSeries(np.random.randn(len(series.sp_values)),
4647
index=sdf.index,
4748
sparse_index=series.sp_index,

bench/bench_take_indexing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from __future__ import print_function
12
import numpy as np
23

34
from pandas import *
45
import pandas._tseries as lib
56

67
from pandas import DataFrame
78
import timeit
9+
from pandas.compat import zip
810

911
setup = """
1012
from pandas import Series
@@ -35,7 +37,7 @@ def _timeit(stmt, size, k=5, iters=1000):
3537
return timer.timeit(n) / n
3638

3739
for sz, its in zip(sizes, iters):
38-
print sz
40+
print(sz)
3941
fancy_2d.append(_timeit('arr[indexer]', sz, iters=its))
4042
take_2d.append(_timeit('arr.take(indexer, axis=0)', sz, iters=its))
4143
cython_2d.append(_timeit('lib.take_axis0(arr, indexer)', sz, iters=its))
@@ -44,7 +46,7 @@ def _timeit(stmt, size, k=5, iters=1000):
4446
'take': take_2d,
4547
'cython': cython_2d})
4648

47-
print df
49+
print(df)
4850

4951
from pandas.rpy.common import r
5052
r('mat <- matrix(rnorm(50000), nrow=10000, ncol=5)')

0 commit comments

Comments
 (0)