predictably.config_context#

predictably.config_context(*, dataframe_backend: Literal['polars', 'pandas', 'fugue', 'input'] | None = None, math_backend: Literal['predictably', 'numba', 'numpy'] | None = None, print_changed_only: bool | None = None, display: Literal['text', 'diagram'] | None = None, local_threadsafe: bool = False) Iterator[None][source]#

Context manager for global configuration.

Provides the ability to run code using different configuration without having to update the global config.

Parameters:
dataframe_backend{“polars”, “pandas”, “fugue”, “input”}, default=None

The dataframe backend to use internally in predictably.

  • If “polars”, “pandas”, or “fugue” then input data will be converted to the specified type as necessary.

  • If “input” then the dataframe will be processed using the type of its input. For example, if the input is a polars.DataFrame or polars.LazyFrame it will be processed as a polars.LazyFrame.

math_backend{“predictably”, “numba”, “numpy”}, default=None

The backend to use for mathematical processing.

  • If “predictably” than predictably’s internal methods, including pre-compiled Rust code.

  • If “numba” or “numpy” then math and linear algebra processing will use numba or numpy, respectively.

print_changed_onlybool, default=None

If True, only the parameters that were set to non-default values will be printed when printing a Model instance. For example, print(Model()) while True will only print ‘Model()’, but would print ‘Model(C=1.0, cache_size=200, …)’ with all the unchanged parameters when False. If None, the existing value won’t change.

display{‘text’, ‘diagram’}, default=None

If ‘diagram’, instances inheriting from BaseOBject will be displayed as a diagram in a Jupyter lab or notebook context. If ‘text’, instances inheriting from BaseObject will be displayed as text. If None, the existing value won’t change.

local_threadsafebool, default=False

If False, set the config as default for all threads.

Yields:
None

No output returned.

See also

get_default_config

Retrieve predictably’s default configuration.

get_config

Retrieve current values of the global configuration.

set_config

Set global configuration.

reset_config

Reset configuration to predictably default.

Notes

All settings, not just those presently modified, will be returned to their previous values when the context manager is exited.

Examples

>>> from predictably import config_context
>>> with config_context(display='diagram'):
...     pass