Skip to content

Commit 2d997af

Browse files
committed
PERF: Fix performance benchmark suite so it runs on Python 3
1 parent 4677306 commit 2d997af

Some content is hidden

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

65 files changed

+259
-208
lines changed

asv_bench/asv.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// The Pythons you'd like to test against. If not provided, defaults
2727
// to the current version of Python used to run `asv`.
2828
// "pythons": ["2.7", "3.4"],
29-
"pythons": ["2.7"],
29+
"pythons": ["2.7", "3.4"],
3030

3131
// The matrix of dependencies to test. Each key is the name of a
3232
// package (in PyPI) and the values are version numbers. An empty

asv_bench/benchmarks/attrs_caching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class getattr_dataframe_index(object):

asv_bench/benchmarks/binary_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
import pandas.computation.expressions as expr
33

44

asv_bench/benchmarks/categoricals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class concat_categorical(object):

asv_bench/benchmarks/ctors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class frame_constructor_ndarray(object):

asv_bench/benchmarks/eval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from pandas_vb_common import *
2-
import pandas.computation.expressions as expr
1+
from .pandas_vb_common import *
32
import pandas as pd
3+
import pandas.computation.expressions as expr
44

55

66
class eval_frame_add_all_threads(object):

asv_bench/benchmarks/frame_ctor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
try:
33
from pandas.tseries.offsets import *
44
except:
@@ -1657,7 +1657,7 @@ class frame_ctor_nested_dict_int64(object):
16571657
goal_time = 0.2
16581658

16591659
def setup(self):
1660-
self.data = dict(((i, dict(((j, float(j)) for j in xrange(100)))) for i in xrange(2000)))
1660+
self.data = dict(((i, dict(((j, float(j)) for j in range(100)))) for i in xrange(2000)))
16611661

16621662
def time_frame_ctor_nested_dict_int64(self):
16631663
DataFrame(self.data)

asv_bench/benchmarks/frame_methods.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class frame_apply_axis_1(object):
@@ -398,7 +398,7 @@ def time_frame_from_records_generator(self):
398398
self.df = DataFrame.from_records(self.get_data())
399399

400400
def get_data(self, n=100000):
401-
return ((x, (x * 20), (x * 100)) for x in xrange(n))
401+
return ((x, (x * 20), (x * 100)) for x in range(n))
402402

403403

404404
class frame_from_records_generator_nrows(object):
@@ -408,7 +408,7 @@ def time_frame_from_records_generator_nrows(self):
408408
self.df = DataFrame.from_records(self.get_data(), nrows=1000)
409409

410410
def get_data(self, n=100000):
411-
return ((x, (x * 20), (x * 100)) for x in xrange(n))
411+
return ((x, (x * 20), (x * 100)) for x in range(n))
412412

413413

414414
class frame_get_dtype_counts(object):
@@ -443,11 +443,11 @@ def g(self):
443443
pass
444444

445445
def h(self):
446-
for i in xrange(10000):
446+
for i in range(10000):
447447
self.df2['A']
448448

449449
def j(self):
450-
for i in xrange(10000):
450+
for i in range(10000):
451451
self.df3[0]
452452

453453

@@ -473,11 +473,11 @@ def g(self):
473473
pass
474474

475475
def h(self):
476-
for i in xrange(10000):
476+
for i in range(10000):
477477
self.df2['A']
478478

479479
def j(self):
480-
for i in xrange(10000):
480+
for i in range(10000):
481481
self.df3[0]
482482

483483

@@ -607,11 +607,11 @@ def g(self):
607607
pass
608608

609609
def h(self):
610-
for i in xrange(10000):
610+
for i in range(10000):
611611
self.df2['A']
612612

613613
def j(self):
614-
for i in xrange(10000):
614+
for i in range(10000):
615615
self.df3[0]
616616

617617

@@ -637,11 +637,11 @@ def g(self):
637637
pass
638638

639639
def h(self):
640-
for i in xrange(10000):
640+
for i in range(10000):
641641
self.df2['A']
642642

643643
def j(self):
644-
for i in xrange(10000):
644+
for i in range(10000):
645645
self.df3[0]
646646

647647

asv_bench/benchmarks/gil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
from pandas.core import common as com
33
try:
44
from pandas.util.testing import test_parallel

asv_bench/benchmarks/groupby.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from pandas_vb_common import *
2-
from itertools import product
1+
from .pandas_vb_common import *
32
from string import ascii_letters, digits
3+
from itertools import product
44

55

66
class groupby_agg_builtins1(object):
@@ -1535,12 +1535,12 @@ def setup(self):
15351535
self.secid_max = int('F0000000', 16)
15361536
self.step = ((self.secid_max - self.secid_min) // (self.n_securities - 1))
15371537
self.security_ids = map((lambda x: hex(x)[2:10].upper()), range(self.secid_min, (self.secid_max + 1), self.step))
1538-
self.data_index = MultiIndex(levels=[self.dates.values, self.security_ids], labels=[[i for i in xrange(self.n_dates) for _ in xrange(self.n_securities)], (range(self.n_securities) * self.n_dates)], names=['date', 'security_id'])
1538+
self.data_index = MultiIndex(levels=[self.dates.values, self.security_ids], labels=[[i for i in range(self.n_dates) for _ in xrange(self.n_securities)], (range(self.n_securities) * self.n_dates)], names=['date', 'security_id'])
15391539
self.n_data = len(self.data_index)
1540-
self.columns = Index(['factor{}'.format(i) for i in xrange(1, (self.n_columns + 1))])
1540+
self.columns = Index(['factor{}'.format(i) for i in range(1, (self.n_columns + 1))])
15411541
self.data = DataFrame(np.random.randn(self.n_data, self.n_columns), index=self.data_index, columns=self.columns)
15421542
self.step = int((self.n_data * self.share_na))
1543-
for column_index in xrange(self.n_columns):
1543+
for column_index in range(self.n_columns):
15441544
self.index = column_index
15451545
while (self.index < self.n_data):
15461546
self.data.set_value(self.data_index[self.index], self.columns[column_index], np.nan)
@@ -1644,12 +1644,12 @@ def setup(self):
16441644
self.secid_max = int('F0000000', 16)
16451645
self.step = ((self.secid_max - self.secid_min) // (self.n_securities - 1))
16461646
self.security_ids = map((lambda x: hex(x)[2:10].upper()), range(self.secid_min, (self.secid_max + 1), self.step))
1647-
self.data_index = MultiIndex(levels=[self.dates.values, self.security_ids], labels=[[i for i in xrange(self.n_dates) for _ in xrange(self.n_securities)], (range(self.n_securities) * self.n_dates)], names=['date', 'security_id'])
1647+
self.data_index = MultiIndex(levels=[self.dates.values, self.security_ids], labels=[[i for i in range(self.n_dates) for _ in xrange(self.n_securities)], (range(self.n_securities) * self.n_dates)], names=['date', 'security_id'])
16481648
self.n_data = len(self.data_index)
1649-
self.columns = Index(['factor{}'.format(i) for i in xrange(1, (self.n_columns + 1))])
1649+
self.columns = Index(['factor{}'.format(i) for i in range(1, (self.n_columns + 1))])
16501650
self.data = DataFrame(np.random.randn(self.n_data, self.n_columns), index=self.data_index, columns=self.columns)
16511651
self.step = int((self.n_data * self.share_na))
1652-
for column_index in xrange(self.n_columns):
1652+
for column_index in range(self.n_columns):
16531653
self.index = column_index
16541654
while (self.index < self.n_data):
16551655
self.data.set_value(self.data_index[self.index], self.columns[column_index], np.nan)

asv_bench/benchmarks/hdfstore_bench.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
import os
33

44

@@ -152,7 +152,7 @@ class read_store_table_panel(object):
152152

153153
def setup(self):
154154
self.f = '__test__.h5'
155-
self.p = Panel(randn(20, 1000, 25), items=[('Item%03d' % i) for i in xrange(20)], major_axis=date_range('1/1/2000', periods=1000), minor_axis=[('E%03d' % i) for i in xrange(25)])
155+
self.p = Panel(randn(20, 1000, 25), items=[('Item%03d' % i) for i in range(20)], major_axis=date_range('1/1/2000', periods=1000), minor_axis=[('E%03d' % i) for i in range(25)])
156156
self.remove(self.f)
157157
self.store = HDFStore(self.f)
158158
self.store.append('p1', self.p)
@@ -267,7 +267,7 @@ class write_store_table_dc(object):
267267

268268
def setup(self):
269269
self.f = '__test__.h5'
270-
self.df = DataFrame(np.random.randn(10000, 10), columns=[('C%03d' % i) for i in xrange(10)])
270+
self.df = DataFrame(np.random.randn(10000, 10), columns=[('C%03d' % i) for i in range(10)])
271271
self.remove(self.f)
272272
self.store = HDFStore(self.f)
273273

@@ -312,7 +312,7 @@ class write_store_table_panel(object):
312312

313313
def setup(self):
314314
self.f = '__test__.h5'
315-
self.p = Panel(randn(20, 1000, 25), items=[('Item%03d' % i) for i in xrange(20)], major_axis=date_range('1/1/2000', periods=1000), minor_axis=[('E%03d' % i) for i in xrange(25)])
315+
self.p = Panel(randn(20, 1000, 25), items=[('Item%03d' % i) for i in range(20)], major_axis=date_range('1/1/2000', periods=1000), minor_axis=[('E%03d' % i) for i in range(25)])
316316
self.remove(self.f)
317317
self.store = HDFStore(self.f)
318318

asv_bench/benchmarks/index_object.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class datetime_index_intersection(object):
@@ -248,7 +248,7 @@ class multiindex_from_product(object):
248248
goal_time = 0.2
249249

250250
def setup(self):
251-
self.iterables = [tm.makeStringIndex(10000), xrange(20)]
251+
self.iterables = [tm.makeStringIndex(10000), range(20)]
252252

253253
def time_multiindex_from_product(self):
254254
MultiIndex.from_product(self.iterables)

asv_bench/benchmarks/inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
import pandas as pd
33

44

asv_bench/benchmarks/io_bench.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
from pandas import concat, Timestamp
3-
from StringIO import StringIO
3+
try:
4+
from StringIO import StringIO
5+
except ImportError:
6+
from io import StringIO
47

58

69
class frame_to_csv(object):
@@ -53,7 +56,7 @@ def time_frame_to_csv_mixed(self):
5356
self.df.to_csv('__test__.csv')
5457

5558
def create_cols(self, name):
56-
return [('%s%03d' % (name, i)) for i in xrange(5)]
59+
return [('%s%03d' % (name, i)) for i in range(5)]
5760

5861

5962
class read_csv_infer_datetime_format_custom(object):

asv_bench/benchmarks/io_sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from pandas_vb_common import *
2-
from sqlalchemy import create_engine
3-
import sqlite3
41
import sqlalchemy
2+
from .pandas_vb_common import *
3+
import sqlite3
4+
from sqlalchemy import create_engine
55

66

77
class sql_datetime_read_and_parse_sqlalchemy(object):

asv_bench/benchmarks/join_merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class append_frame_single_homogenous(object):

asv_bench/benchmarks/miscellaneous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
from pandas.util.decorators import cache_readonly
33

44

asv_bench/benchmarks/packers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
from .pandas_vb_common import *
12
from numpy.random import randint
23
import pandas as pd
34
from collections import OrderedDict
45
from pandas.compat import BytesIO
56
import sqlite3
6-
from pandas_vb_common import *
77
import os
88
from sqlalchemy import create_engine
99
import numpy as np

asv_bench/benchmarks/pandas_vb_common.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from pandas import *
2+
import pandas as pd
3+
from datetime import timedelta
4+
from numpy.random import randn
5+
from numpy.random import randint
6+
from numpy.random import permutation
7+
import pandas.util.testing as tm
8+
import random
9+
import numpy as np
10+
try:
11+
from pandas.compat import range
12+
except ImportError:
13+
pass
14+
15+
np.random.seed(1234)
16+
try:
17+
import pandas._tseries as lib
18+
except:
19+
import pandas.lib as lib
20+
21+
try:
22+
Panel = WidePanel
23+
except Exception:
24+
pass
25+
26+
# didn't add to namespace until later
27+
try:
28+
from pandas.core.index import MultiIndex
29+
except ImportError:
30+
pass

asv_bench/benchmarks/panel_ctor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class panel_from_dict_all_different_indexes(object):
@@ -8,7 +8,7 @@ def setup(self):
88
self.data_frames = {}
99
self.start = datetime(1990, 1, 1)
1010
self.end = datetime(2012, 1, 1)
11-
for x in xrange(100):
11+
for x in range(100):
1212
self.end += timedelta(days=1)
1313
self.dr = np.asarray(date_range(self.start, self.end))
1414
self.df = DataFrame({'a': ([0] * len(self.dr)), 'b': ([1] * len(self.dr)), 'c': ([2] * len(self.dr)), }, index=self.dr)
@@ -23,7 +23,7 @@ class panel_from_dict_equiv_indexes(object):
2323

2424
def setup(self):
2525
self.data_frames = {}
26-
for x in xrange(100):
26+
for x in range(100):
2727
self.dr = np.asarray(DatetimeIndex(start=datetime(1990, 1, 1), end=datetime(2012, 1, 1), freq=datetools.Day(1)))
2828
self.df = DataFrame({'a': ([0] * len(self.dr)), 'b': ([1] * len(self.dr)), 'c': ([2] * len(self.dr)), }, index=self.dr)
2929
self.data_frames[x] = self.df
@@ -38,7 +38,7 @@ class panel_from_dict_same_index(object):
3838
def setup(self):
3939
self.dr = np.asarray(DatetimeIndex(start=datetime(1990, 1, 1), end=datetime(2012, 1, 1), freq=datetools.Day(1)))
4040
self.data_frames = {}
41-
for x in xrange(100):
41+
for x in range(100):
4242
self.df = DataFrame({'a': ([0] * len(self.dr)), 'b': ([1] * len(self.dr)), 'c': ([2] * len(self.dr)), }, index=self.dr)
4343
self.data_frames[x] = self.df
4444

@@ -53,7 +53,7 @@ def setup(self):
5353
self.data_frames = {}
5454
self.start = datetime(1990, 1, 1)
5555
self.end = datetime(2012, 1, 1)
56-
for x in xrange(100):
56+
for x in range(100):
5757
if (x == 50):
5858
self.end += timedelta(days=1)
5959
self.dr = np.asarray(date_range(self.start, self.end))

asv_bench/benchmarks/panel_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22

33

44
class panel_pct_change_items(object):

asv_bench/benchmarks/parser_vb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from cStringIO import StringIO
2-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
32
import os
43
from pandas import read_csv, read_table
4+
try:
5+
from cStringIO import StringIO
6+
except ImportError:
7+
from io import StringIO
58

69

710
class read_csv_comment2(object):

asv_bench/benchmarks/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
try:
33
from pandas import date_range
44
except ImportError:

asv_bench/benchmarks/reindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pandas_vb_common import *
1+
from .pandas_vb_common import *
22
from random import shuffle
33

44

0 commit comments

Comments
 (0)