Skip to content

Commit 1abb116

Browse files
committed
PERF: perf improvements in DataFrame construction with a non-daily datelike index (GH6479)
Dynamic vbenches
1 parent ed20b1d commit 1abb116

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

vb_suite/frame_ctor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
from vbench.benchmark import Benchmark
22
from datetime import datetime
3+
try:
4+
import pandas.tseries.offsets as offsets
5+
except:
6+
import pandas.core.datetools as offsets
37

48
common_setup = """from pandas_vb_common import *
9+
try:
10+
from pandas.tseries.offsets import *
11+
except:
12+
from pandas.core.datetools import *
513
"""
614

715
#----------------------------------------------------------------------
@@ -36,6 +44,21 @@
3644
"""
3745
frame_ctor_nested_dict_int64 = Benchmark("DataFrame(data)", setup)
3846

47+
# dynamically generate benchmarks for every offset
48+
dynamic_benchmarks = {}
49+
n_steps = [1, 2]
50+
for offset in offsets.__all__:
51+
for n in n_steps:
52+
setup = common_setup + """
53+
df = DataFrame(np.random.randn(1000,10),index=date_range('1/1/1900',periods=1000,freq={}({})))
54+
d = dict([ (col,df[col]) for col in df.columns ])
55+
""".format(offset, n)
56+
key = 'frame_ctor_dtindex_{}({})'.format(offset, n)
57+
dynamic_benchmarks[key] = Benchmark("DataFrame(d)", setup, name=key)
58+
59+
# Have to stuff them in globals() so vbench detects them
60+
globals().update(dynamic_benchmarks)
61+
3962
# from a mi-series
4063
setup = common_setup + """
4164
mi = MultiIndex.from_tuples([(x,y) for x in range(100) for y in range(100)])

0 commit comments

Comments
 (0)