-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests][python] reduce unnecessary data loading in tests (#3486)
* [ci] [python] reduce unnecessary data loading in tests * add profiling files to gitignore * just use cache() * default on cache size * patch lru_cache on Python 2.7 * linting * reduce duplicated code * missing warnings * fix imports * fix lru_cache backport * missing kwargs * Apply suggestions from code review Co-authored-by: Nikita Titov <[email protected]> * reduce duplicated code * cache in test_plotting Co-authored-by: Nikita Titov <[email protected]>
- Loading branch information
1 parent
5cc9e67
commit 03c4d45
Showing
7 changed files
with
59 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,6 +318,8 @@ htmlcov/ | |
.coverage.* | ||
.cache | ||
nosetests.xml | ||
prof/ | ||
*.prof | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
Empty file.
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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# coding: utf-8 | ||
import sklearn.datasets | ||
|
||
try: | ||
from functools import lru_cache | ||
except ImportError: | ||
import warnings | ||
warnings.warn("Could not import functools.lru_cache", RuntimeWarning) | ||
|
||
def lru_cache(maxsize=None): | ||
cache = {} | ||
|
||
def _lru_wrapper(user_function): | ||
def wrapper(*args, **kwargs): | ||
arg_key = (args, tuple(kwargs.items())) | ||
if arg_key not in cache: | ||
cache[arg_key] = user_function(*args, **kwargs) | ||
return cache[arg_key] | ||
return wrapper | ||
return _lru_wrapper | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def load_boston(**kwargs): | ||
return sklearn.datasets.load_boston(**kwargs) | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def load_breast_cancer(**kwargs): | ||
return sklearn.datasets.load_breast_cancer(**kwargs) | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def load_digits(**kwargs): | ||
return sklearn.datasets.load_digits(**kwargs) | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def load_iris(**kwargs): | ||
return sklearn.datasets.load_iris(**kwargs) | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def load_linnerud(**kwargs): | ||
return sklearn.datasets.load_linnerud(**kwargs) |