Skip to content

Commit 6121367

Browse files
committed
Pop off the recently added filter after testing for deprecation warnings.
1 parent 777f57a commit 6121367

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sklearn/base.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,17 @@ def get_params(self, deep=True):
203203
# We need deprecation warnings to always be on for this to work.
204204
# This is set in utils/__init__.py but it gets overwritten
205205
# when running under python3 somehow.
206-
warnings.simplefilter("always", DeprecationWarning)
207206
for key in self._get_param_names():
208207
# catch deprecation warnings
209-
with warnings.catch_warnings(record=True) as w:
210-
value = getattr(self, key, None)
211-
if len(w) and w[0].category == DeprecationWarning:
208+
warnings.simplefilter("always", DeprecationWarning)
209+
try:
210+
with warnings.catch_warnings(record=True) as w:
211+
value = getattr(self, key, None)
212+
if len(w) and w[0].category == DeprecationWarning:
212213
# if the parameter is deprecated, don't show it
213-
continue
214+
continue
215+
finally:
216+
warnings.filters.pop(0)
214217

215218
# XXX: should we rather test if instance of estimator?
216219
if deep and hasattr(value, 'get_params'):

0 commit comments

Comments
 (0)