some new features
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
"""Tests for making sure experimental imports work as expected."""
|
||||
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
from sklearn.utils._testing import assert_run_python_script_without_output
|
||||
from sklearn.utils.fixes import _IS_WASM
|
||||
|
||||
|
||||
@pytest.mark.xfail(_IS_WASM, reason="cannot start subprocess")
|
||||
def test_import_raises_warning():
|
||||
code = """
|
||||
import pytest
|
||||
with pytest.warns(UserWarning, match="it is not needed to import"):
|
||||
from sklearn.experimental import enable_hist_gradient_boosting # noqa
|
||||
"""
|
||||
pattern = "it is not needed to import enable_hist_gradient_boosting anymore"
|
||||
assert_run_python_script_without_output(textwrap.dedent(code), pattern=pattern)
|
||||
@ -0,0 +1,51 @@
|
||||
"""Tests for making sure experimental imports work as expected."""
|
||||
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
from sklearn.utils._testing import assert_run_python_script_without_output
|
||||
from sklearn.utils.fixes import _IS_WASM
|
||||
|
||||
|
||||
@pytest.mark.xfail(_IS_WASM, reason="cannot start subprocess")
|
||||
def test_imports_strategies():
|
||||
# Make sure different import strategies work or fail as expected.
|
||||
|
||||
# Since Python caches the imported modules, we need to run a child process
|
||||
# for every test case. Else, the tests would not be independent
|
||||
# (manually removing the imports from the cache (sys.modules) is not
|
||||
# recommended and can lead to many complications).
|
||||
pattern = "IterativeImputer is experimental"
|
||||
good_import = """
|
||||
from sklearn.experimental import enable_iterative_imputer
|
||||
from sklearn.impute import IterativeImputer
|
||||
"""
|
||||
assert_run_python_script_without_output(
|
||||
textwrap.dedent(good_import), pattern=pattern
|
||||
)
|
||||
|
||||
good_import_with_ensemble_first = """
|
||||
import sklearn.ensemble
|
||||
from sklearn.experimental import enable_iterative_imputer
|
||||
from sklearn.impute import IterativeImputer
|
||||
"""
|
||||
assert_run_python_script_without_output(
|
||||
textwrap.dedent(good_import_with_ensemble_first),
|
||||
pattern=pattern,
|
||||
)
|
||||
|
||||
bad_imports = f"""
|
||||
import pytest
|
||||
|
||||
with pytest.raises(ImportError, match={pattern!r}):
|
||||
from sklearn.impute import IterativeImputer
|
||||
|
||||
import sklearn.experimental
|
||||
with pytest.raises(ImportError, match={pattern!r}):
|
||||
from sklearn.impute import IterativeImputer
|
||||
"""
|
||||
assert_run_python_script_without_output(
|
||||
textwrap.dedent(bad_imports),
|
||||
pattern=pattern,
|
||||
)
|
||||
@ -0,0 +1,53 @@
|
||||
"""Tests for making sure experimental imports work as expected."""
|
||||
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
from sklearn.utils._testing import assert_run_python_script_without_output
|
||||
from sklearn.utils.fixes import _IS_WASM
|
||||
|
||||
|
||||
@pytest.mark.xfail(_IS_WASM, reason="cannot start subprocess")
|
||||
def test_imports_strategies():
|
||||
# Make sure different import strategies work or fail as expected.
|
||||
|
||||
# Since Python caches the imported modules, we need to run a child process
|
||||
# for every test case. Else, the tests would not be independent
|
||||
# (manually removing the imports from the cache (sys.modules) is not
|
||||
# recommended and can lead to many complications).
|
||||
pattern = "Halving(Grid|Random)SearchCV is experimental"
|
||||
good_import = """
|
||||
from sklearn.experimental import enable_halving_search_cv
|
||||
from sklearn.model_selection import HalvingGridSearchCV
|
||||
from sklearn.model_selection import HalvingRandomSearchCV
|
||||
"""
|
||||
assert_run_python_script_without_output(
|
||||
textwrap.dedent(good_import), pattern=pattern
|
||||
)
|
||||
|
||||
good_import_with_model_selection_first = """
|
||||
import sklearn.model_selection
|
||||
from sklearn.experimental import enable_halving_search_cv
|
||||
from sklearn.model_selection import HalvingGridSearchCV
|
||||
from sklearn.model_selection import HalvingRandomSearchCV
|
||||
"""
|
||||
assert_run_python_script_without_output(
|
||||
textwrap.dedent(good_import_with_model_selection_first),
|
||||
pattern=pattern,
|
||||
)
|
||||
|
||||
bad_imports = f"""
|
||||
import pytest
|
||||
|
||||
with pytest.raises(ImportError, match={pattern!r}):
|
||||
from sklearn.model_selection import HalvingGridSearchCV
|
||||
|
||||
import sklearn.experimental
|
||||
with pytest.raises(ImportError, match={pattern!r}):
|
||||
from sklearn.model_selection import HalvingRandomSearchCV
|
||||
"""
|
||||
assert_run_python_script_without_output(
|
||||
textwrap.dedent(bad_imports),
|
||||
pattern=pattern,
|
||||
)
|
||||
Reference in New Issue
Block a user