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.
- Parameters:
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.
A context manager for hiding objects in the global scope.
- Parameters:
- Raises:
NonGlobalHidden – If ‘hidden’ is declared inside a function, class or method.
HiddenAlreadyUsedInThisContext – If the ‘hidden’ context manager is used more than once in the same context.
- Yields:
None
Notes
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.