8000 MNT Change print_changed_only default to True (#17061) · scikit-learn/scikit-learn@964c830 · GitHub
[go: up one dir, main page]

Skip to content

Commit 964c830

Browse files
authored
MNT Change print_changed_only default to True (#17061)
1 parent fc00415 commit 964c830

File tree

8 files changed

+38
-33
lines changed

8 files changed

+38
-33
lines changed

conftest.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,6 @@ def pytest_unconfigure(config):
9999
del sys._is_pytest_session
100100

101101

102-
def pytest_runtest_setup(item):
103-
if isinstance(item, DoctestItem):
104-
set_config(print_changed_only=True)
105-
106-
107-
def pytest_runtest_teardown(item, nextitem):
108-
if isinstance(item, DoctestItem):
109-
set_config(print_changed_only=False)
110-
111-
112102
# TODO: Remove when modules are deprecated in 0.24
113103
# Configures pytest to ignore deprecated modules.
114104
collect_ignore_glob = [

doc/conf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,3 @@ def setup(app):
392392
warnings.filterwarnings("ignore", category=UserWarning,
393393
message='Matplotlib is currently using agg, which is a'
394394
' non-GUI backend, so cannot show the figure.')
395-
396-
# Reduces the output of estimators
397-
sklearn.set_config(print_changed_only=True)

doc/whats_new/v0.23.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,14 @@ Miscellaneous
564564
error message is raised when y was expected but None was passed.
565565
:pr:`16622` by `Nicolas Hug`_.
566566

567+
- |API| The default setting `print_changed_only` has been changed from False
568+
to True. This means that the `repr` of estimators is now more concise and
569+
only shows the parameters whose default value has been changed when
570+
printing an estimator. You can restore the previous behaviour by using
571+
`sklearn.set_config(print_changed_only=False)`. Also, note that it is
572+
always possible to quickly inspect the parameters of any estimator using
573+
`est.get_params(deep=False)`. :pr:`17061` by `Nicolas Hug`_.
574+
567575
Code and Documentation Contributors
568576
-----------------------------------
569577

sklearn/_config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
_global_config = {
77
'assume_finite': bool(os.environ.get('SKLEARN_ASSUME_FINITE', False)),
88
'working_memory': int(os.environ.get('SKLEARN_WORKING_MEMORY', 1024)),
9-
'print_changed_only': False,
9+
'print_changed_only': True,
1010
}
1111

1212

@@ -93,9 +93,12 @@ def config_context(**new_config):
9393
print_changed_only : bool, optional
9494
If True, only the parameters that were set to non-default
9595
values will be printed when printing an estimator. For example,
96-
``print(SVC())`` while True will only print 'SVC()' while the default
97-
behaviour would be to print 'SVC(C=1.0, cache_size=200, ...)' with
98-
all the non-changed parameters.
96+
``print(SVC())`` while True will only print 'SVC()', but would print
97+
'SVC(C=1.0, cache_size=200, ...)' with all the non-changed parameters
98+
when False. Default is True.
99+
100+
.. versionchanged:: 0.23
101+
Default changed from False to True.
99102
100103
Notes
101104
-----

sklearn/tests/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ def test_repr():
211211
test = T(K(), K())
212212
assert (
213213
repr(test) ==
214-
"T(a=K(c=None, d=None), b=K(c=None, d=None))")
214+
"T(a=K(), b=K())")
215215

216216
some_est = T(a=["long_params"] * 1000)
217-
assert len(repr(some_est)) == 495
217+
assert len(repr(some_est)) == 485
218218

219219

220220
def test_str():

sklearn/tests/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
def test_config_context():
66
assert get_config() == {'assume_finite': False, 'working_memory': 1024,
7-
'print_changed_only': False}
7+
'print_changed_only': True}
88

99
# Not using as a context manager affects nothing
1010
config_context(assume_finite=True)
1111
assert get_config()['assume_finite'] is False
1212

1313
with config_context(assume_finite=True):
1414
assert get_config() == {'assume_finite': True, 'working_memory': 1024,
15-
'print_changed_only': False}
15+
'print_changed_only': True}
1616
assert get_config()['assume_finite'] is False
1717

1818
with config_context(assume_finite=True):
@@ -37,7 +37,7 @@ def test_config_context():
3737
assert get_config()['assume_finite'] is True
3838

3939
assert get_config() == {'assume_finite': False, 'working_memory': 1024,
40-
'print_changed_only': False}
40+
'print_changed_only': True}
4141

4242
# No positional arguments
4343
assert_raises(TypeError, config_context, True)

sklearn/utils/tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
3+
import sklearn
4+
5+
6+
@pytest.fixture
7+
def print_changed_only_false():
8+
sklearn.set_config(print_changed_only=False)
9+
yield
10+
sklearn.set_config(print_changed_only=True) # reset to default

sklearn/utils/tests/test_pprint.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def __init__(self, missing_values=np.nan, strategy="mean",
174174
self.copy = copy
175175

176176

177-
def test_basic():
177+
def test_basic(print_changed_only_false):
178178
# Basic pprint test
179179
lr = LogisticRegression()
180180
expected = """
@@ -189,8 +189,7 @@ def test_basic():
189189

190190

191191
def test_changed_only():
192-
# Make sure the changed_only param is correctly used
193-
set_config(print_changed_only=True)
192+
# Make sure the changed_only param is correctly used when True (default)
194193
lr = LogisticRegression(C=99)
195194
expected = """LogisticRegression(C=99)"""
196195
assert lr.__repr__() == expected
@@ -216,10 +215,8 @@ def test_changed_only():
216215
# make sure array parameters don't throw error (see #13583)
217216
repr(LogisticRegressionCV(Cs=np.array([0.1, 1])))
218217

219-
set_config(print_changed_only=False)
220218

221-
222-
def test_pipeline():
219+
def test_pipeline(print_changed_only_false):
223220
# Render a pipeline object
224221
pipeline = make_pipeline(StandardScaler(), LogisticRegression(C=999))
225222
expected = """
@@ -240,7 +237,7 @@ def test_pipeline():
240237
assert pipeline.__repr__() == expected
241238

242239

243-
def test_deeply_nested():
240+
def test_deeply_nested(print_changed_only_false):
244241
# Render a deeply nested estimator
245242
rfe = RFE(RFE(RFE(RFE(RFE(RFE(RFE(LogisticRegression())))))))
246243
expected = """
@@ -277,7 +274,7 @@ def test_deeply_nested():
277274
assert rfe.__repr__() == expected
278275

279276

280-
def test_gridsearch():
277+
def test_gridsearch(print_changed_only_false):
281278
# render a gridsearch
282279
param_grid = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4],
283280
'C': [1, 10, 100, 1000]},
@@ -302,7 +299,7 @@ def test_gridsearch():
302299
assert gs.__repr__() == expected
303300

304301

305-
def test_gridsearch_pipeline():
302+
def test_gridsearch_pipeline(print_changed_only_false):
306303
# render a pipeline inside a gridsearch
307304
pp = _EstimatorPrettyPrinter(compact=True, indent=1, indent_at_name=True)
308305

@@ -372,7 +369,7 @@ def test_gridsearch_pipeline():
372369
assert repr_ == expected
373370

374371

375-
def test_n_max_elements_to_show():
372+
def test_n_max_elements_to_show(print_changed_only_false):
376373

377374
n_max_elements_to_show = 30
378375
pp = _EstimatorPrettyPrinter(
@@ -461,7 +458,7 @@ def test_n_max_elements_to_show():
461458
assert pp.pformat(gs) == expected
462459

463460

464-
def test_bruteforce_ellipsis():
461+
def test_bruteforce_ellipsis(print_changed_only_false):
465462
# Check that the bruteforce ellipsis (used when the number of non-blank
466463
# characters exceeds N_CHAR_MAX) renders correctly.
467464

0 commit comments

Comments
 (0)
0