forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.py
150 lines (117 loc) · 5.05 KB
/
eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from vbench.benchmark import Benchmark
from datetime import datetime
common_setup = """from pandas_vb_common import *
import pandas as pd
df = DataFrame(np.random.randn(20000, 100))
df2 = DataFrame(np.random.randn(20000, 100))
df3 = DataFrame(np.random.randn(20000, 100))
df4 = DataFrame(np.random.randn(20000, 100))
"""
setup = common_setup + """
import pandas.computation.expressions as expr
expr.set_numexpr_threads(1)
"""
SECTION = 'Eval'
#----------------------------------------------------------------------
# binary ops
#----------------------------------------------------------------------
# add
eval_frame_add_all_threads = \
Benchmark("pd.eval('df + df2 + df3 + df4')", common_setup,
name='eval_frame_add_all_threads',
start_date=datetime(2013, 7, 21))
eval_frame_add_one_thread = \
Benchmark("pd.eval('df + df2 + df3 + df4')", setup,
name='eval_frame_add_one_thread',
start_date=datetime(2013, 7, 26))
eval_frame_add_python = \
Benchmark("pd.eval('df + df2 + df3 + df4', engine='python')", common_setup,
name='eval_frame_add_python', start_date=datetime(2013, 7, 21))
eval_frame_add_python_one_thread = \
Benchmark("pd.eval('df + df2 + df3 + df4', engine='python')", setup,
name='eval_frame_add_python_one_thread',
start_date=datetime(2013, 7, 26))
#----------------------------------------------------------------------
# mult
eval_frame_mult_all_threads = \
Benchmark("pd.eval('df * df2 * df3 * df4')", common_setup,
name='eval_frame_mult_all_threads',
start_date=datetime(2013, 7, 21))
eval_frame_mult_one_thread = \
Benchmark("pd.eval('df * df2 * df3 * df4')", setup,
name='eval_frame_mult_one_thread',
start_date=datetime(2013, 7, 26))
eval_frame_mult_python = \
Benchmark("pd.eval('df * df2 * df3 * df4', engine='python')",
common_setup,
name='eval_frame_mult_python', start_date=datetime(2013, 7, 21))
eval_frame_mult_python_one_thread = \
Benchmark("pd.eval('df * df2 * df3 * df4', engine='python')", setup,
name='eval_frame_mult_python_one_thread',
start_date=datetime(2013, 7, 26))
#----------------------------------------------------------------------
# multi and
eval_frame_and_all_threads = \
Benchmark("pd.eval('(df > 0) & (df2 > 0) & (df3 > 0) & (df4 > 0)')",
common_setup,
name='eval_frame_and_all_threads',
start_date=datetime(2013, 7, 21))
eval_frame_and_one_thread = \
Benchmark("pd.eval('(df > 0) & (df2 > 0) & (df3 > 0) & (df4 > 0)')", setup,
name='eval_frame_and_one_thread',
start_date=datetime(2013, 7, 26))
eval_frame_and_python = \
Benchmark("pd.eval('(df > 0) & (df2 > 0) & (df3 > 0) & (df4 > 0)', engine='python')",
common_setup, name='eval_frame_and_python',
start_date=datetime(2013, 7, 21))
eval_frame_and_one_thread = \
Benchmark("pd.eval('(df > 0) & (df2 > 0) & (df3 > 0) & (df4 > 0)', engine='python')",
setup,
name='eval_frame_and_python_one_thread',
start_date=datetime(2013, 7, 26))
#--------------------------------------------------------------------
# chained comp
eval_frame_chained_cmp_all_threads = \
Benchmark("pd.eval('df < df2 < df3 < df4')", common_setup,
name='eval_frame_chained_cmp_all_threads',
start_date=datetime(2013, 7, 21))
eval_frame_chained_cmp_one_thread = \
Benchmark("pd.eval('df < df2 < df3 < df4')", setup,
name='eval_frame_chained_cmp_one_thread',
start_date=datetime(2013, 7, 26))
eval_frame_chained_cmp_python = \
Benchmark("pd.eval('df < df2 < df3 < df4', engine='python')",
common_setup, name='eval_frame_chained_cmp_python',
start_date=datetime(2013, 7, 26))
eval_frame_chained_cmp_one_thread = \
Benchmark("pd.eval('df < df2 < df3 < df4', engine='python')", setup,
name='eval_frame_chained_cmp_python_one_thread',
start_date=datetime(2013, 7, 26))
common_setup = """from pandas_vb_common import *
"""
setup = common_setup + """
N = 1000000
halfway = N // 2 - 1
index = date_range('20010101', periods=N, freq='T')
s = Series(index)
ts = s.iloc[halfway]
"""
series_setup = setup + """
df = DataFrame({'dates': s.values})
"""
query_datetime_series = Benchmark("df.query('dates < @ts')",
series_setup,
start_date=datetime(2013, 9, 27))
index_setup = setup + """
df = DataFrame({'a': np.random.randn(N)}, index=index)
"""
query_datetime_index = Benchmark("df.query('index < @ts')",
index_setup, start_date=datetime(2013, 9, 27))
setup = setup + """
N = 1000000
df = DataFrame({'a': np.random.randn(N)})
min_val = df['a'].min()
max_val = df['a'].max()
"""
query_with_boolean_selection = Benchmark("df.query('(a >= @min_val) & (a <= @max_val)')",
setup, start_date=datetime(2013, 9, 27))