-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
POC: dynamically choose which asvs to run #40005
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
Closed
Closed
Changes from all commits
Commits
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,132 @@ | ||
""" | ||
Try to identify which asvs can be ignored for a PR. | ||
""" | ||
import os | ||
import shlex | ||
import subprocess | ||
|
||
here = os.path.dirname(__file__) # assumes repo directory | ||
bmark_dir = os.path.join("asv_bench", "benchmarks") | ||
|
||
|
||
def find_changed(): | ||
""" | ||
Find the names of files changes (compared to master) in this branch. | ||
""" | ||
cmd = "git diff upstream/master --name-only" | ||
|
||
p = subprocess.Popen( | ||
shlex.split(cmd), | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
close_fds=True, | ||
) | ||
stdout, stderr = p.communicate() | ||
|
||
flist = stdout.decode("utf-8").splitlines() | ||
return flist | ||
|
||
|
||
def find_asv_paths(): | ||
""" | ||
Find all of our asv benchmark files. | ||
""" | ||
bmarks = os.path.join(here, bmark_dir) | ||
walk = os.scandir(bmarks) | ||
walk = [ | ||
x | ||
for x in walk | ||
if x.is_file() | ||
and x.name.endswith(".py") | ||
and x.name not in ["__init__.py", "pandas_vb_common.py"] | ||
] | ||
|
||
paths = [x.path.replace(bmarks, "").lstrip(os.sep) for x in walk] | ||
return paths | ||
|
||
|
||
def trim_asv_paths(): | ||
""" | ||
Exclude benchmark files we can be confident are not affected | ||
by this PR. | ||
""" | ||
flist = find_changed() | ||
|
||
changed = [x for x in flist if "pandas/" in x and "pandas/tests/" not in x] | ||
|
||
asv_paths = find_asv_paths() | ||
|
||
if "setup.py" in flist: | ||
# We can't exclude anything | ||
return asv_paths | ||
if any("_libs/src" in x for x in changed): | ||
# We can't exclude anything | ||
return asv_paths | ||
if not any("_libs/tslibs" in x for x in changed): | ||
# If nothing in tslibs changed, then none of the tslibs asvs should | ||
# be affected | ||
asv_paths = [x for x in asv_paths if not x.startswith("tslibs/")] | ||
if not any("_libs/" in x for x in changed): | ||
asv_paths = [ | ||
x for x in asv_paths if x not in ["libs.py", "indexing_engines.py"] | ||
] | ||
# TODO: | ||
# inference.MaybeConvertNumeric | ||
# dtypes.InferDtypes | ||
# algorithms.MaybeConvertObjects # (not 100% disjoint) | ||
return asv_paths | ||
|
||
|
||
def path_to_module(path: str) -> str: | ||
""" | ||
>>> path = "asv_bench/benchmarks/ctors.py" | ||
>>> path_to_module(path) | ||
'ctors' | ||
|
||
>>> path = "asv_bench/benchmarks/tslibs/fields.py" | ||
>>> path_to_module(path) | ||
'tslibs.fields' | ||
""" | ||
assert path.startswith(bmark_dir) | ||
assert path.endswith(".py") | ||
|
||
name = path.replace(bmark_dir, "").strip(os.sep) | ||
name = name[:-3] | ||
name = name.replace(os.sep, ".") | ||
return name | ||
|
||
|
||
def run_relevant_asvs(): | ||
paths = trim_asv_paths() | ||
|
||
names = [path_to_module(x) for x in paths] | ||
|
||
pattern = "-b ".join(names) | ||
run_asvs(pattern) | ||
|
||
|
||
def run_asvs(pattern: str): | ||
|
||
cmd = ( | ||
"asv continuous " | ||
"-E virtualenv " | ||
"-f 1.05 " | ||
"--record-samples --append-samples " | ||
f"master HEAD -b {pattern}" | ||
) | ||
|
||
os.chdir("asv_bench") | ||
try: | ||
p = subprocess.Popen( | ||
shlex.split(cmd), | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
close_fds=True, | ||
) | ||
stdout, stderr = p.communicate() | ||
finally: | ||
os.chdir(here) | ||
|
||
stdout = stdout.decode("utf-8") | ||
stderr = stderr.decode("utf-8") | ||
return stdout, stderr |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have dependencies for these mostly declared in the
setup.py
file. In the future could potentially use that to refine this further