Skip to content

fix: don't globally silence warnings on importing sklearn_tuner#123

Open
Nas01010101 wants to merge 1 commit into
huawei-noah:masterfrom
Nas01010101:fix/sklearn-tuner-global-warnings
Open

fix: don't globally silence warnings on importing sklearn_tuner#123
Nas01010101 wants to merge 1 commit into
huawei-noah:masterfrom
Nas01010101:fix/sklearn-tuner-global-warnings

Conversation

@Nas01010101
Copy link
Copy Markdown

Summary

hebo/sklearn_tuner.py calls warnings.filterwarnings('ignore') at module import time, which installs a process-wide 'ignore' filter at the front of warnings.filters. Simply importing the module therefore silences warnings in the entire host program — including the caller's own warnings (related to #58).

Fix

Remove the import-time global call and scope the suppression to the optimisation loop using warnings.catch_warnings(), which restores the caller's filter state on exit:

with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    ...  # tuning loop

Tests

Adds test/test_sklearn_tuner_warnings.py — two regression tests: (1) importing the module installs no global 'ignore' filter; (2) running the tuner does not leak filters into the caller. Both fail before the fix, pass after.

2 passed

Relates to #58.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 29, 2026

CLA assistant check
All committers have signed the CLA.

`sklearn_tuner.py` calls `warnings.filterwarnings('ignore')` at module
import time, which installs a process-wide 'ignore' filter at the front
of `warnings.filters`. Merely importing the module therefore silences
every warning in the host program, hiding the caller's own warnings.

Scope the suppression to the optimisation loop with
`warnings.catch_warnings()`, which restores the caller's filters on
exit. Adds regression tests asserting that import installs no global
'ignore' filter and that tuning does not leak filter changes.
@Nas01010101 Nas01010101 force-pushed the fix/sklearn-tuner-global-warnings branch from 97d28f0 to 4c3fc0e Compare May 29, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants