diff --git a/maint_tools/test_docstrings.py b/maint_tools/test_docstrings.py index 0cdebc4cfaf42..83aadcd046350 100644 --- a/maint_tools/test_docstrings.py +++ b/maint_tools/test_docstrings.py @@ -12,7 +12,6 @@ numpydoc_validation = pytest.importorskip("numpydoc.validate") FUNCTION_DOCSTRING_IGNORE_LIST = [ - "sklearn._config.config_context", "sklearn._config.get_config", "sklearn.base.clone", "sklearn.cluster._affinity_propagation.affinity_propagation", diff --git a/sklearn/_config.py b/sklearn/_config.py index 21c3cc1b4d142..ad66a403d3ef1 100644 --- a/sklearn/_config.py +++ b/sklearn/_config.py @@ -98,40 +98,55 @@ def set_config( @contextmanager -def config_context(**new_config): - """Context manager for global scikit-learn configuration +def config_context( + *, assume_finite=None, working_memory=None, print_changed_only=None, display=None +): + """Context manager for global scikit-learn configuration. Parameters ---------- - assume_finite : bool, default=False + assume_finite : bool, default=None If True, validation for finiteness will be skipped, saving time, but leading to potential crashes. If False, validation for finiteness will be performed, - avoiding error. Global default: False. + avoiding error. If None, the existing value won't change. + The default value is False. - working_memory : int, default=1024 + working_memory : int, default=None If set, scikit-learn will attempt to limit the size of temporary arrays to this number of MiB (per job when parallelised), often saving both computation time and memory on expensive operations that can be - performed in chunks. Global default: 1024. + performed in chunks. If None, the existing value won't change. + The default value is 1024. - print_changed_only : bool, default=True + print_changed_only : bool, default=None If True, only the parameters that were set to non-default values will be printed when printing an estimator. For example, ``print(SVC())`` while True will only print 'SVC()', but would print 'SVC(C=1.0, cache_size=200, ...)' with all the non-changed parameters - when False. Default is True. + when False. If None, the existing value won't change. + The default value is True. .. versionchanged:: 0.23 Default changed from False to True. - display : {'text', 'diagram'}, default='text' + display : {'text', 'diagram'}, default=None If 'diagram', estimators will be displayed as a diagram in a Jupyter lab or notebook context. If 'text', estimators will be displayed as - text. Default is 'text'. + text. If None, the existing value won't change. + The default value is 'text'. .. versionadded:: 0.23 + Yields + ------ + None. + + See Also + -------- + set_config : Set global scikit-learn configuration. + get_config : Retrieve current values of the global configuration. + Notes ----- All settings, not just those presently modified, will be returned to @@ -149,14 +164,14 @@ def config_context(**new_config): Traceback (most recent call last): ... ValueError: Input contains NaN... - - See Also - -------- - set_config : Set global scikit-learn configuration. - get_config : Retrieve current values of the global configuration. """ old_config = get_config() - set_config(**new_config) + set_config( + assume_finite=assume_finite, + working_memory=working_memory, + print_changed_only=print_changed_only, + display=display, + ) try: yield