pavise.types

Type definitions for Pavise.

class pavise.types.NotRequiredColumn[source]

Bases: Generic[T]

Marker type for optional columns in Protocol schemas.

Use this to indicate that a column may not exist in the DataFrame. If the column is present, it will be validated according to its type.

Key differences: - Optional[T]: Column must exist, but can contain None values - NotRequiredColumn[T]: Column can be missing, but if present must have type T - NotRequiredColumn[Optional[T]]: Column can be missing, and if present can contain None

Example

>>> from typing import Protocol, Optional
>>> from pavise.pandas import DataFrame
>>> from pavise.types import NotRequiredColumn
>>>
>>> class UserSchema(Protocol):
...     user_id: int
...     name: str
...     age: NotRequiredColumn[int]  # Column can be missing
...     email: NotRequiredColumn[Optional[str]]  # Missing or nullable
>>>
>>> # Both are valid
>>> df1 = DataFrame[UserSchema](pd.DataFrame({"user_id": [1], "name": ["Alice"]}))
>>> df2 = DataFrame[UserSchema](
...     pd.DataFrame({"user_id": [1], "name": ["Alice"], "age": [25]})
... )
classmethod __class_getitem__(item)[source]

Support NotRequiredColumn[T] syntax.

Parameters:

item (type)

Return type:

type