Options
Utilities for configuring Pandas Checks options.
This module provides functions for setting and managing global options for Pandas Checks, including formatting and disabling checks and assertions.
_initialize_format_options(options=None)
Initializes or resets Pandas Checks formatting options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options
|
Union[List[str], None]
|
A list of option names to initialize or reset. If None, all formatting options will be initialized or reset. |
None
|
Returns: None
Note
We separate this function from _initialize_options() so user can reset just formatting without changing mode
_initialize_options()
Initializes (or resets) all Pandas Checks options to their default values.
Returns:
Type | Description |
---|---|
None
|
None |
Note
We separate this function from _initialize_format_options() so user can reset just formatting if desired without changing mode
_is_callable(object)
Validator function to check if an object is callable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object
|
Any
|
The Python object to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if object is callable or None, False otherwise. |
_register_option(name, default_value, description, validator)
Registers a Pandas Checks option in the global Pandas context manager.
If the option has already been registered, reset its value.
This method enables setting global formatting for Pandas Checks results and storing variables that will persist across Pandas method chains, which return newly initialized DataFrames at each method (and so reset the DataFrame's attributes).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the option to register. |
required |
default_value
|
Any
|
The default value for the option. |
required |
description
|
str
|
A description of the option. |
required |
validator
|
Callable
|
A function to validate the option value. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Note
For more details on the arguments, see the documentation for pandas._config.config.register_option()
_set_option(option, value)
Updates the value of a Pandas Checks option in the global Pandas context manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
option
|
str
|
The name of the option to set. |
required |
value
|
Any
|
The value to set for the option. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
AttributeError
|
If the |
describe_options()
Prints all global options for Pandas Checks, their default values, and current values.
NOTE: Does not use custom_print_fn. Always prints to stdout.
Returns:
Type | Description |
---|---|
None
|
None |
disable_checks(enable_asserts=True)
Turns off all calls to Pandas Checks methods and optionally enables or disables check.assert_data(). Does not modify the DataFrame itself.
If this function is called, subequent calls to .check functions will not be run.
Typically used to 1) Globally switch off Pandas Checks, such as during production. or 2) Temporarily switch off Pandas Checks, such as for a stable part of a notebook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_asserts
|
bool
|
Whether to also run calls to Pandas Checks .check.assert_data() |
True
|
Returns:
Type | Description |
---|---|
None
|
None |
enable_checks(enable_asserts=True)
Turns on Pandas Checks globally. Subsequent calls to .check methods will be run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_asserts
|
bool
|
Whether to also enable or disable check.assert_data(). |
True
|
Returns:
Type | Description |
---|---|
None
|
None |
get_mode()
Returns whether Pandas Checks is currently running checks and assertions.
Returns:
Type | Description |
---|---|
Dict[str, bool]
|
A dictionary containing the current settings. |
reset_format()
Globally restores all Pandas Checks formatting options to their default "factory" settings.
Returns:
Type | Description |
---|---|
None
|
None |
set_custom_print_fn(custom_print_fn, print_to_stdout=None)
Specifies, or resets, a custom print function for Pandas Checks results. Optionally also (re)sets whether check results should be shown on screen.
Feature idea from @alexblakes, inspired by scikit-lego's sklego.pandas_utils.log_step. https://github.com/cparmet/pandas-checks/issues/48
Example usage:
# To display check results on screen and in the log at LEVEL=INFO:
import pandas_checks as pdc
pdc.set_custom_print_fn(logging.info)
# To _only_ send check results to the log, not display them on screen:
pdc.set_custom_print_fn(custom_print_fn=logging.info, print_to_stdout=False)
# To reset these settings to their defaults:
pdc.set_custom_print_fn(custom_print_fn=None, print_to_stdout=True)
NOTE: Only plain text is sent to custom_print_fn. Plots, HTML, and colored text will not be sent. set_option(precision) also does not apply to custom_print_fn.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
custom_print_fn
|
Union[Callable, None]
|
A callable function that takes a single argument (the text to print). If None, or not passed, disables custom print. |
required |
print_to_stdout
|
Union[bool, None]
|
Whether to also display check results on screen. If None, does not change the current setting for print_to_stdout (in case the caller only wants to configure custom_print_fn). |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
set_format(**kwargs)
Configures selected formatting options for Pandas Checks. Run pandas_checks.describe_options() to see a list of available options.
For example, set_format(check_text_tag= "h1", use_emojis=False`) will globally change Pandas Checks to display text results as H1 headings and remove all emojis.
Returns:
Type | Description |
---|---|
None
|
None |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Pairs of setting name and its new value. |
{}
|
set_mode(enable_checks, enable_asserts)
Configures the operation mode for Pandas Checks globally.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_checks
|
bool
|
Whether to run any Pandas Checks methods globally. Does not affect .check.assert_data(). |
required |
enable_asserts
|
bool
|
Whether to run calls to .check.assert_data() globally. |
required |
Returns:
Type | Description |
---|---|
None
|
None |