-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: update query/eval figures on performance comparison #48368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jorisvandenbossche
merged 9 commits into
pandas-dev:main
from
carla-alves-24:shiny-new-feature_carla
Oct 28, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
335bd2a
update eval/query_performance
dc0181d
final update eval/query_performance
934bc25
run black
5467e74
pre-commit
91ed98d
Merge branch 'pandas-dev:main' into shiny-new-feature_carla
carla-alves-24 1f0e87d
Merge remote-tracking branch 'upstream/main' into shiny-new-feature_c…
jorisvandenbossche 69fac81
rerun benchmark script
jorisvandenbossche 0dfd1c7
Update doc/source/user_guide/enhancingperf.rst
jorisvandenbossche 77cc760
Update doc/source/user_guide/indexing.rst
jorisvandenbossche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
from timeit import repeat as timeit | ||
|
||
import numpy as np | ||
import seaborn as sns | ||
|
||
from pandas import DataFrame | ||
|
||
setup_common = """from pandas import DataFrame | ||
from numpy.random import randn | ||
df = DataFrame(randn(%d, 3), columns=list('abc')) | ||
%s""" | ||
|
||
setup_with = "s = 'a + b * (c ** 2 + b ** 2 - a) / (a * c) ** 3'" | ||
|
||
|
||
def bench_with(n, times=10, repeat=3, engine="numexpr"): | ||
return ( | ||
np.array( | ||
timeit( | ||
"df.eval(s, engine=%r)" % engine, | ||
setup=setup_common % (n, setup_with), | ||
repeat=repeat, | ||
number=times, | ||
) | ||
) | ||
/ times | ||
) | ||
|
||
|
||
setup_subset = "s = 'a <= b <= c ** 2 + b ** 2 - a and b > c'" | ||
|
||
|
||
def bench_subset(n, times=20, repeat=3, engine="numexpr"): | ||
return ( | ||
np.array( | ||
timeit( | ||
"df.query(s, engine=%r)" % engine, | ||
setup=setup_common % (n, setup_subset), | ||
repeat=repeat, | ||
number=times, | ||
) | ||
) | ||
/ times | ||
) | ||
|
||
|
||
def bench(mn=3, mx=7, num=100, engines=("python", "numexpr"), verbose=False): | ||
r = np.logspace(mn, mx, num=num).round().astype(int) | ||
|
||
ev = DataFrame(np.empty((num, len(engines))), columns=engines) | ||
qu = ev.copy(deep=True) | ||
|
||
ev["size"] = qu["size"] = r | ||
|
||
for engine in engines: | ||
for i, n in enumerate(r): | ||
if verbose & (i % 10 == 0): | ||
print("engine: %r, i == %d" % (engine, i)) | ||
ev_times = bench_with(n, times=1, repeat=1, engine=engine) | ||
ev.loc[i, engine] = np.mean(ev_times) | ||
qu_times = bench_subset(n, times=1, repeat=1, engine=engine) | ||
qu.loc[i, engine] = np.mean(qu_times) | ||
|
||
return ev, qu | ||
|
||
|
||
def plot_perf(df, engines, title, filename=None): | ||
from matplotlib.pyplot import figure | ||
|
||
sns.set() | ||
sns.set_palette("Set2") | ||
|
||
fig = figure(figsize=(4, 3), dpi=120) | ||
ax = fig.add_subplot(111) | ||
|
||
for engine in engines: | ||
ax.loglog(df["size"], df[engine], label=engine, lw=2) | ||
|
||
ax.set_xlabel("Number of Rows") | ||
ax.set_ylabel("Time (s)") | ||
ax.set_title(title) | ||
ax.legend(loc="best") | ||
ax.tick_params(top=False, right=False) | ||
|
||
fig.tight_layout() | ||
|
||
if filename is not None: | ||
fig.savefig(filename) | ||
|
||
|
||
if __name__ == "__main__": | ||
import os | ||
|
||
pandas_dir = os.path.dirname( | ||
os.path.dirname(os.path.abspath(os.path.dirname(__file__))) | ||
) | ||
static_path = os.path.join(pandas_dir, "doc", "source", "_static") | ||
|
||
join = lambda p: os.path.join(static_path, p) | ||
|
||
fn = join("eval-query-perf-data.h5") | ||
|
||
engines = "python", "numexpr" | ||
|
||
ev, qu = bench(verbose=True) # only this one | ||
|
||
plot_perf(ev, engines, "DataFrame.eval()", filename=join("eval-perf.png")) | ||
plot_perf(qu, engines, "DataFrame.query()", filename=join("query-perf.png")) |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.