pandera.extensions

Extensions module, for backwards compatibility.

class pandera.extensions.CheckType(value)[source]

Bases: Enum

Check types for registered check methods.

VECTORIZED = 1

Check applied to a Series or DataFrame

ELEMENT_WISE = 2

Check applied to an element of a Series or DataFrame

GROUPBY = 3

Check applied to dictionary of Series or DataFrames.

pandera.extensions.register_builtin_check(fn=None, strategy=None, constraint=None, _check_cls=<class 'pandera.api.checks.Check'>, aliases=None, **outer_kwargs)[source]

Register a check method to the Check namespace.

This is the primary way for extending the Check api to define additional built-in checks.

Parameters:
  • strategy (UnionType[Callable, None]) – legacy hypothesis strategy adapter with the signature (pandera_dtype, strategy=None, **statistics) -> SearchStrategy.

  • constraint (UnionType[Callable, None]) – optional constraint adapter that takes the check’s statistics as kwargs and returns a FieldConstraints. When present, the constraint aggregator merges this with sibling constraints and emits a single hypothesis strategy, avoiding .filter chaining for built-in checks. See specs/optimized-strategies.md.

pandera.extensions.register_builtin_hypothesis(**kwargs)[source]

Register a new hypothesis.

pandera.extensions.register_check_method(check_fn=None, *, statistics=None, supported_types=None, check_type='vectorized', strategy=None, constraint=None)[source]

Registers a function as a Check method.

See the user guide for more details.

Parameters:
  • check_fn – check function to register. The function should take one positional argument for the object to validate and additional keyword-only arguments for the check statistics.

  • statistics (UnionType[list[str], None]) – list of keyword-only arguments in the check_fn, which serve as the statistics needed to serialize/de-serialize the check and generate data if a strategy function is provided.

  • supported_types (Union[type, tuple, list, None]) – the pandas type(s) supported by the check function. Valid values are pd.DataFrame, pd.Series, ps.DataFrame, or a list/tuple of (pa.DataFrame, pa.Series, ps.DataFrame) if both types are supported. Valid values are pd.DataFrame, pd.Series, ps.DataFrame, or a list/tuple of (pa.DataFrame, pa.Series, ps.DataFrame) if both types are supported.

  • check_type (Union[CheckType, str]) –

    the expected input of the check function. Valid values are CheckType enums or {"vectorized", "element_wise", "groupby"}. The input signature of check_fn is determined by this argument:

    • if vectorized, the first positional argument of check_fn should be one of the supported_types.

    • if element_wise, the first positional argument of check_fn should be a single scalar element in the pandas Series or DataFrame.

    • if groupby, the first positional argument of check_fn should be a dictionary mapping group names to subsets of the Series or DataFrame.

  • strategy – data-generation strategy associated with the check function.

  • constraint – optional constraint adapter for the optimised constraint-aggregator path. Receives the check’s statistics as kwargs and returns a FieldConstraints. When present, sibling built-in checks no longer chain .filter calls on top of one another; the merged constraint set is compiled to a single hypothesis strategy. See specs/optimized-strategies.md.

Returns:

register check function wrapper.

pandera.extensions.register_check_statistics(statistics_args)[source]

Decorator to set statistics based on Check method.