scikit-learn/doc/conftest.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

161 lines
5.1 KiB
Python
Raw Normal View History

import os
from os.path import exists
from os.path import join
from os import environ
import warnings
from sklearn.utils import IS_PYPY
from sklearn.utils._testing import SkipTest
from sklearn.utils._testing import check_skip_network
[MRG] CI Push Scipy minimum version to 1.1.0. Remove Python 3.6 from builds. (#20069) * Push scipy min version to 1.0.0 * Update all ubuntu images to 20.04 focal. * Add ubuntu images 18.04 bionic and scipy fron conda-forge. * Fix conditions. * Pin python 3.6 for ubuntu bionic. * Change pipeline name. * Change matrix element name. * Keep python 3.9 from system not conda in Ubuntu 20.04. * Remove python directive when unnecessary. * Cleanup. * Downgrade to python 3.6 as scipy 1.0.0 is incompatible with 3.8. * Fix comment. * Fix comment. * Pin pytest again as we are forced to use 3.6. * Move to conda installer for 32bit linux. * Install miniconda for ubuntu 32bit. * Install wget for ubuntu 32bit. * Revert 32bit OS to ubuntu bionic 18.04. * Install scipy from pip in 32bit system. * Fix doctest failures. * Revert example rendering. * Relax pytest version in ubuntu install. * Skip failing tests. * Put comment at the right place. * Remove python3.6. Ubuntu32 still needs to be adapted. * Push numpy and scipy min versions for compatibility with 3.7. * Push matplotlib min version for compatibility with 3.7. Install numpy via pip in 32bit linux. * Install numpy before scipy in Linux 32bit. * Pass numpy version to linux32. * Test 32bit architecture on debian buster (still exists for 32bit with python 3.7). * Install matplotlib from distribution. * Syntax error... * Stick to the numpy debian version to avoid Expected 124 from C header, got 112 from PyObject error. * Clean comments. * Revert skip in doctest to check with new dependencies. * Rename distrib. * Skip again... * Fix test on check_array. * Remove comment and fix lint at the same time. * Clean import. * Increase atol in test_derivatives to make the test pass in py37_conda_openblas environment. * Avoid sparse matrix dependent on scipy version. * Skip docstring test for pandas versions less then 1.1.0. * Fix lint error. * Empty commit to force checks. * Add minimal dependencies in changelog. * Update to python 3.7 CircleCI and Travis builds. * Move to debian buster for python3.7 dependencies. * Fix the container tag. * Lower the minimal pandas version for compatibility with python 3.7.
2021-05-18 22:09:36 +08:00
from sklearn.utils.fixes import parse_version
from sklearn.datasets import get_data_home
from sklearn.datasets._base import _pkl_filepath
from sklearn.datasets._twenty_newsgroups import CACHE_NAME
def setup_labeled_faces():
data_home = get_data_home()
if not exists(join(data_home, "lfw_home")):
raise SkipTest("Skipping dataset loading doctests")
def setup_rcv1():
check_skip_network()
# skip the test in rcv1.rst if the dataset is not already loaded
rcv1_dir = join(get_data_home(), "RCV1")
if not exists(rcv1_dir):
raise SkipTest("Download RCV1 dataset to run this test.")
def setup_twenty_newsgroups():
cache_path = _pkl_filepath(get_data_home(), CACHE_NAME)
if not exists(cache_path):
raise SkipTest("Skipping dataset loading doctests")
def setup_working_with_text_data():
if IS_PYPY and os.environ.get("CI", None):
raise SkipTest("Skipping too slow test with PyPy on CI")
check_skip_network()
cache_path = _pkl_filepath(get_data_home(), CACHE_NAME)
if not exists(cache_path):
raise SkipTest("Skipping dataset loading doctests")
def setup_loading_other_datasets():
try:
import pandas # noqa
except ImportError:
raise SkipTest("Skipping loading_other_datasets.rst, pandas not installed")
# checks SKLEARN_SKIP_NETWORK_TESTS to see if test should run
run_network_tests = environ.get("SKLEARN_SKIP_NETWORK_TESTS", "1") == "0"
if not run_network_tests:
raise SkipTest(
"Skipping loading_other_datasets.rst, tests can be "
2021-07-25 02:18:43 +08:00
"enabled by setting SKLEARN_SKIP_NETWORK_TESTS=0"
)
def setup_compose():
try:
import pandas # noqa
except ImportError:
raise SkipTest("Skipping compose.rst, pandas not installed")
def setup_impute():
try:
import pandas # noqa
except ImportError:
raise SkipTest("Skipping impute.rst, pandas not installed")
FEA Successive halving for faster parameter search (#13900) * More flexible grid search interface * added info dict parameter * Put back removed test * renamed info into more_results * Passed grroups as well since we need n_to use get_n_splits(X, y, groups) * port * pep8 * dabl -> sklearn * add _required_parameters * skipping check in rst file if pandas not installed * Update sklearn/model_selection/_search_successive_halving.py Co-Authored-By: Joel Nothman <joel.nothman@gmail.com> * renamed into GridHalvingSearchCV and RandomHalvingSearchCV * Addressed thomas' comments * repr * removed passing group as a parameter to evaluate_candidates * Joels comments * pep8 * reorganized user user guide * renaming * update user guide * remove groups support + pass fit_params * parameter renaming * pep8 * r_i -> resource_iter * fixed r_i issues * examples + removed use of word budget * Added inpute checking tests * added cv_resutlts_ user guide * minor title change * fixed doc layout * Addressed some comments * properly pass down fit_params * change default value of force_exhaust_resources and update doc * should fix doc * Used check_fit_params * Update section about min_resources and number of candidates * Clarified ratio section * Use ~ to refer to classes * fixed doc checks * Apply suggestions from code review Co-authored-by: Joel Nothman <joel.nothman@gmail.com> * Addressed easy comments from Joel * missed some * updated docstring of run_search * Used f strings instead of format * remove candidate duplication checks * fix example * Addressed easy comments * rotate ticks labels * Added discussion in the intro as suggested by Joel * Split examples into sections * minor changes * remove force_exhaust_budget and introduce min_resources=exhaust * some minor validation * Added a n_resources_ attribute * update examples * Addressed comments * passing CV instead of X,y * minor revert for handling fit_params * updated docs * fix len * whatsnew * Add test for sampling when all_list * minor change to top-k * Force CV splits to be consistent across calls * reorder parameters * reduced diff * added tests for top_k * put back doc for groups * not sure what went wrong * put import at its place * some comment * Addressed comments * Added tests for cv_results_ and base estimator inputs * pep8 * avoid monkeypatching * rename df * use Joel's suggestions for testing masks * Made it experimental * Should fix docs * whats new entry * Apply suggestions from code review Co-authored-by: Andreas Mueller <t3kcit@gmail.com> * Addressed comments to docs * Addressed comments in examples * minor doc update * minor renaming in UG * forgot some * some sad note about splitter statefulness :'( * Addressed comments * ratio -> factor Co-authored-by: Joel Nothman <joel.nothman@gmail.com> Co-authored-by: Andreas Mueller <t3kcit@gmail.com>
2020-09-09 23:12:35 +08:00
def setup_grid_search():
try:
import pandas # noqa
except ImportError:
raise SkipTest("Skipping grid_search.rst, pandas not installed")
def setup_preprocessing():
try:
import pandas # noqa
[MRG] CI Push Scipy minimum version to 1.1.0. Remove Python 3.6 from builds. (#20069) * Push scipy min version to 1.0.0 * Update all ubuntu images to 20.04 focal. * Add ubuntu images 18.04 bionic and scipy fron conda-forge. * Fix conditions. * Pin python 3.6 for ubuntu bionic. * Change pipeline name. * Change matrix element name. * Keep python 3.9 from system not conda in Ubuntu 20.04. * Remove python directive when unnecessary. * Cleanup. * Downgrade to python 3.6 as scipy 1.0.0 is incompatible with 3.8. * Fix comment. * Fix comment. * Pin pytest again as we are forced to use 3.6. * Move to conda installer for 32bit linux. * Install miniconda for ubuntu 32bit. * Install wget for ubuntu 32bit. * Revert 32bit OS to ubuntu bionic 18.04. * Install scipy from pip in 32bit system. * Fix doctest failures. * Revert example rendering. * Relax pytest version in ubuntu install. * Skip failing tests. * Put comment at the right place. * Remove python3.6. Ubuntu32 still needs to be adapted. * Push numpy and scipy min versions for compatibility with 3.7. * Push matplotlib min version for compatibility with 3.7. Install numpy via pip in 32bit linux. * Install numpy before scipy in Linux 32bit. * Pass numpy version to linux32. * Test 32bit architecture on debian buster (still exists for 32bit with python 3.7). * Install matplotlib from distribution. * Syntax error... * Stick to the numpy debian version to avoid Expected 124 from C header, got 112 from PyObject error. * Clean comments. * Revert skip in doctest to check with new dependencies. * Rename distrib. * Skip again... * Fix test on check_array. * Remove comment and fix lint at the same time. * Clean import. * Increase atol in test_derivatives to make the test pass in py37_conda_openblas environment. * Avoid sparse matrix dependent on scipy version. * Skip docstring test for pandas versions less then 1.1.0. * Fix lint error. * Empty commit to force checks. * Add minimal dependencies in changelog. * Update to python 3.7 CircleCI and Travis builds. * Move to debian buster for python3.7 dependencies. * Fix the container tag. * Lower the minimal pandas version for compatibility with python 3.7.
2021-05-18 22:09:36 +08:00
if parse_version(pandas.__version__) < parse_version("1.1.0"):
raise SkipTest("Skipping preprocessing.rst, pandas version < 1.1.0")
except ImportError:
raise SkipTest("Skipping preprocessing.rst, pandas not installed")
def setup_unsupervised_learning():
try:
import skimage # noqa
except ImportError:
raise SkipTest("Skipping unsupervised_learning.rst, scikit-image not installed")
# ignore deprecation warnings from scipy.misc.face
warnings.filterwarnings(
"ignore", "The binary mode of fromstring", DeprecationWarning
)
def skip_if_matplotlib_not_installed(fname):
try:
import matplotlib # noqa
except ImportError:
basename = os.path.basename(fname)
raise SkipTest(f"Skipping doctests for {basename}, matplotlib not installed")
def pytest_runtest_setup(item):
fname = item.fspath.strpath
# normalise filename to use forward slashes on Windows for easier handling
# later
fname = fname.replace(os.sep, "/")
2018-06-20 12:33:12 +08:00
is_index = fname.endswith("datasets/index.rst")
if fname.endswith("datasets/labeled_faces.rst") or is_index:
setup_labeled_faces()
2018-06-20 12:33:12 +08:00
elif fname.endswith("datasets/rcv1.rst") or is_index:
setup_rcv1()
2018-06-20 12:33:12 +08:00
elif fname.endswith("datasets/twenty_newsgroups.rst") or is_index:
setup_twenty_newsgroups()
2018-06-20 12:33:12 +08:00
elif (
fname.endswith("tutorial/text_analytics/working_with_text_data.rst") or is_index
):
setup_working_with_text_data()
2018-06-20 12:33:12 +08:00
elif fname.endswith("modules/compose.rst") or is_index:
setup_compose()
elif IS_PYPY and fname.endswith("modules/feature_extraction.rst"):
raise SkipTest("FeatureHasher is not compatible with PyPy")
elif fname.endswith("datasets/loading_other_datasets.rst"):
setup_loading_other_datasets()
elif fname.endswith("modules/impute.rst"):
setup_impute()
FEA Successive halving for faster parameter search (#13900) * More flexible grid search interface * added info dict parameter * Put back removed test * renamed info into more_results * Passed grroups as well since we need n_to use get_n_splits(X, y, groups) * port * pep8 * dabl -> sklearn * add _required_parameters * skipping check in rst file if pandas not installed * Update sklearn/model_selection/_search_successive_halving.py Co-Authored-By: Joel Nothman <joel.nothman@gmail.com> * renamed into GridHalvingSearchCV and RandomHalvingSearchCV * Addressed thomas' comments * repr * removed passing group as a parameter to evaluate_candidates * Joels comments * pep8 * reorganized user user guide * renaming * update user guide * remove groups support + pass fit_params * parameter renaming * pep8 * r_i -> resource_iter * fixed r_i issues * examples + removed use of word budget * Added inpute checking tests * added cv_resutlts_ user guide * minor title change * fixed doc layout * Addressed some comments * properly pass down fit_params * change default value of force_exhaust_resources and update doc * should fix doc * Used check_fit_params * Update section about min_resources and number of candidates * Clarified ratio section * Use ~ to refer to classes * fixed doc checks * Apply suggestions from code review Co-authored-by: Joel Nothman <joel.nothman@gmail.com> * Addressed easy comments from Joel * missed some * updated docstring of run_search * Used f strings instead of format * remove candidate duplication checks * fix example * Addressed easy comments * rotate ticks labels * Added discussion in the intro as suggested by Joel * Split examples into sections * minor changes * remove force_exhaust_budget and introduce min_resources=exhaust * some minor validation * Added a n_resources_ attribute * update examples * Addressed comments * passing CV instead of X,y * minor revert for handling fit_params * updated docs * fix len * whatsnew * Add test for sampling when all_list * minor change to top-k * Force CV splits to be consistent across calls * reorder parameters * reduced diff * added tests for top_k * put back doc for groups * not sure what went wrong * put import at its place * some comment * Addressed comments * Added tests for cv_results_ and base estimator inputs * pep8 * avoid monkeypatching * rename df * use Joel's suggestions for testing masks * Made it experimental * Should fix docs * whats new entry * Apply suggestions from code review Co-authored-by: Andreas Mueller <t3kcit@gmail.com> * Addressed comments to docs * Addressed comments in examples * minor doc update * minor renaming in UG * forgot some * some sad note about splitter statefulness :'( * Addressed comments * ratio -> factor Co-authored-by: Joel Nothman <joel.nothman@gmail.com> Co-authored-by: Andreas Mueller <t3kcit@gmail.com>
2020-09-09 23:12:35 +08:00
elif fname.endswith("modules/grid_search.rst"):
setup_grid_search()
elif fname.endswith("modules/preprocessing.rst"):
setup_preprocessing()
elif fname.endswith("statistical_inference/unsupervised_learning.rst"):
setup_unsupervised_learning()
rst_files_requiring_matplotlib = [
"modules/partial_dependence.rst",
"modules/tree.rst",
"tutorial/statistical_inference/settings.rst",
"tutorial/statistical_inference/supervised_learning.rst",
]
for each in rst_files_requiring_matplotlib:
if fname.endswith(each):
skip_if_matplotlib_not_installed(fname)
def pytest_configure(config):
# Use matplotlib agg backend during the tests including doctests
try:
import matplotlib
matplotlib.use("agg")
except ImportError:
pass