skcriteria.utils.cmanagers module

Multiple context managers to use inside scikit-criteria.

skcriteria.utils.cmanagers.df_temporal_header(df, header, name=None)[source]

Temporarily replaces a DataFrame columns names.

Optionally also assign another name to the columns.

  • header (sequence) – The new names of the columns.

  • name (str or None (default None)) – New name for the index containing the columns in the DataFrame. If ‘None’ the original name of the columns present in the DataFrame is preserved.

exception skcriteria.utils.cmanagers.HiddenAlreadyUsedInThisContext[source]

Bases: RuntimeError

Raised when a context attempts to use the ‘hidden’ context manager more than once within the same scope.

exception skcriteria.utils.cmanagers.NonGlobalHidden[source]

Bases: RuntimeError

Exception raised when the ‘hidden’ decorator is used in a context that is not the global scope of a module.

This exception indicates that the ‘hidden’ decorator should only be applied globally, outside of any functions or methods, and an attempt to use it within a local context (e.g., inside a function or method) has been detected.

skcriteria.utils.cmanagers.hidden(*, hide_this=True, dry=False)[source]

A context manager for hiding objects in the global scope.

  • hide_this (bool, optional) – Whether to hide the ‘hidden’ context manager itself and/or the hidden module. Defaults to True.

  • dry (bool, optional, default False) – If is True, the objects are not hide. Useful for testing.




  • This context manager is intended to be used globally (outside any functions or methods).

  • It hides objects within the global scope for the duration of the context.

Implementation Details

  • The context manager retrieves the current frame and ensures it is used globally.

  • It captures the state of the global scope before entering the context.

  • Objects introduced within the context are hidden in the global scope.

  • The ‘__dir__’ attribute of the global scope is customized to include logic to hide the objects introduced within the context.