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

Skip to content

Commit 91215fc

Browse files
glemaitremajauharthomasjpfan
committed
DOC Ensures that config_context passes numpydoc validation (#21426)
Co-authored-by: majauhar <[email protected]> Co-authored-by: Thomas J. Fan <[email protected]>
1 parent 0dc76d5 commit 91215fc

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

maint_tools/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
numpydoc_validation = pytest.importorskip("numpydoc.validate")
1313

1414
FUNCTION_DOCSTRING_IGNORE_LIST = [
15-
"sklearn._config.config_context",
1615
"sklearn._config.get_config",
1716
"sklearn.base.clone",
1817
"sklearn.cluster._affinity_propagation.affinity_propagation",

sklearn/_config.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,40 +98,55 @@ def set_config(
9898

9999

100100
@contextmanager
101-
def config_context(**new_config):
102-
"""Context manager for global scikit-learn configuration
101+
def config_context(
102+
*, assume_finite=None, working_memory=None, print_changed_only=None, display=None
103+
):
104+
"""Context manager for global scikit-learn configuration.
103105
104106
Parameters
105107
----------
106-
assume_finite : bool, default=False
108+
assume_finite : bool, default=None
107109
If True, validation for finiteness will be skipped,
108110
saving time, but leading to potential crashes. If
109111
False, validation for finiteness will be performed,
110-
avoiding error. Global default: False.
112+
avoiding error. If None, the existing value won't change.
113+
The default value is False.
111114
112-
working_memory : int, default=1024
115+
working_memory : int, default=None
113116
If set, scikit-learn will attempt to limit the size of temporary arrays
114117
to this number of MiB (per job when parallelised), often saving both
115118
computation time and memory on expensive operations that can be
116-
performed in chunks. Global default: 1024.
119+
performed in chunks. If None, the existing value won't change.
120+
The default value is 1024.
117121
118-
print_changed_only : bool, default=True
122+
print_changed_only : bool, default=None
119123
If True, only the parameters that were set to non-default
120124
values will be printed when printing an estimator. For example,
121125
``print(SVC())`` while True will only print 'SVC()', but would print
122126
'SVC(C=1.0, cache_size=200, ...)' with all the non-changed parameters
123-
when False. Default is True.
127+
when False. If None, the existing value won't change.
128+
The default value is True.
124129
125130
.. versionchanged:: 0.23
126131
Default changed from False to True.
127132
128-
display : {'text', 'diagram'}, default='text'
133+
display : {'text', 'diagram'}, default=None
129134
If 'diagram', estimators will be displayed as a diagram in a Jupyter
130135
lab or notebook context. If 'text', estimators will be displayed as
131-
text. Default is 'text'.
136+
text. If None, the existing value won't change.
137+
The default value is 'text'.
132138
133139
.. versionadded:: 0.23
134140
141+
Yields
142+
------
143+
None.
144+
145+
See Also
146+
--------
147+
set_config : Set global scikit-learn configuration.
148+
get_config : Retrieve current values of the global configuration.
149+
135150
Notes
136151
-----
137152
All settings, not just those presently modified, will be returned to
@@ -148,15 +163,15 @@ def config_context(**new_config):
148163
... assert_all_finite([float('nan')])
149164
Traceback (most recent call last):
150165
...
151-
ValueError: Input contains NaN, ...
152-
153-
See Also
154-
--------
155-
set_config : Set global scikit-learn configuration.
156-
get_config : Retrieve current values of the global configuration.
166+
ValueError: Input contains NaN...
157167
"""
158168
old_config = get_config()
159-
set_config(**new_config)
169+
set_config(
170+
assume_finite=assume_finite,
171+
working_memory=working_memory,
172+
print_changed_only=print_changed_only,
173+
display=display,
174+
)
160175

161176
try:
162177
yield

0 commit comments

Comments
 (0)