reset#
- scikitplot.reset(_gallery_conf=None, _fname=None)[source]#
Reset global state for NumPy, scikit-learn, matplotlib, and seaborn.
This function restores common scientific computing and visualization libraries to their default configurations, preventing state leakage between scripts, examples, or plotting sessions.
It is especially useful in: - Documentation builds (e.g., with Sphinx-Gallery) - Interactive notebooks (Jupyter, Colab) - Streamlit or Dash apps (ensuring consistent reruns) - Automated testing pipelines - Educational or demo environments
What gets reset: - NumPy: Restores default error handling (
np.seterr
) and print formatting(
np.set_printoptions
).scikit-learn: Resets global configuration via
sklearn.set_config
, including options likeassume_finite
andworking_memory
.matplotlib: Closes all open figures, resets
rcParams
, and reapplies the default style.seaborn (if installed): Restores default theme and style to avoid residual settings.
- Parameters:
- _gallery_confdict, optional
Required for compatibility with Sphinx-Gallery’s
reset_modules
hook. Not used internally.- _fnamestr, optional
Filename of the current example (provided by Sphinx-Gallery). Not used internally.
See also
reset_numpy
Reset NumPy global state
reset_sklearn
Reset scikit-learn configuration
reset_matplotlib
Reset matplotlib figures and configuration
reset_seaborn
Reset seaborn theme (if available)
Notes
This function is idempotent and safe to call multiple times.
To use with Sphinx-Gallery, register it as:
>>> sphinx_gallery_conf = { ... "reset_modules": "scikitplot.reset", ... }
You can also register it with
atexit
or use it in apytest
fixture:>>> import atexit >>> atexit.register(reset)
>>> import pytest >>> @pytest.fixture(autouse=True) ... def clean_state(): ... yield ... reset()
Examples
>>> from scikitplot._reset import reset >>> reset() # safely restore global state between examples