Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC Ensures that config_context passes numpydoc validation #21426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 29, 2021
1 change: 0 additions & 1 deletion maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 31 additions & 16 deletions sklearn/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down