-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent internal usage of expensive APIs (#10263)
This PR introduces a decorator that can be used to mark APIs that are unnecessarily expensive and should be avoided in internal usage. The decorator does nothing by default, but when the corresponding environment variable is set the decorator wraps decorated functions in a check of the current call stack. If the caller of that API is within the cudf source tree, it will raise an exception that may optionally also indicate an alternate API for developers to use instead. This implementation is completely transparent to users (including having no performance impact aside from some negligible additional import time from applying the decorator) but can be an invaluable tool to developers seeking to reduce Python overheads in cuDF Python. This decorator has been tested and shown to work (both locally and on CI) for `DataFrame.columns`, but those changes are not included in this PR in order to keep the changeset clean. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Bradley Dice (https://github.com/bdice) - AJ Schmidt (https://github.com/ajschmidt8) URL: #10263
- Loading branch information
Showing
3 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,10 +1,41 @@ | ||
# Copyright (c) 2019-2022, NVIDIA CORPORATION. | ||
|
||
import os | ||
import pathlib | ||
|
||
import pytest | ||
|
||
import rmm # noqa: F401 | ||
|
||
_CURRENT_DIRECTORY = str(pathlib.Path(__file__).resolve().parent) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def datadir(): | ||
return pathlib.Path(__file__).parent / "data" | ||
|
||
|
||
# To set and remove the NO_EXTERNAL_ONLY_APIS environment variable we must use | ||
# the sessionstart and sessionfinish hooks rather than a simple autouse, | ||
# session-scope fixture because we need to set these variable before collection | ||
# occurs because the environment variable will be checked as soon as cudf is | ||
# imported anywhere. | ||
def pytest_sessionstart(session): | ||
""" | ||
Called after the Session object has been created and | ||
before performing collection and entering the run test loop. | ||
""" | ||
os.environ["NO_EXTERNAL_ONLY_APIS"] = "1" | ||
os.environ["_CUDF_TEST_ROOT"] = _CURRENT_DIRECTORY | ||
|
||
|
||
def pytest_sessionfinish(session, exitstatus): | ||
""" | ||
Called after whole test run finished, right before | ||
returning the exit status to the system. | ||
""" | ||
try: | ||
del os.environ["NO_EXTERNAL_ONLY_APIS"] | ||
del os.environ["_CUDF_TEST_ROOT"] | ||
except KeyError: | ||
pass |
This file contains 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