pandera.api.tensordict.components.TensorΒΆ

class pandera.api.tensordict.components.Tensor(dtype=None, shape=None, checks=None, nullable=False, coerce=False, name=None, required=True)[source]ΒΆ

Validate a single tensor entry in a TensorDict.

Analogous to Column for DataFrames and DataVar for xarray Datasets.

Create tensor validator.

Parameters:
  • dtype (Any) – PyTorch dtype (e.g., torch.float32, torch.int64). If a string is provided, it will be converted to the corresponding torch.dtype.

  • shape (UnionType[tuple[UnionType[int, None], …], None]) – Expected shape tuple. Use None for flexible dimensions. For example, (None, 10) allows any batch size with 10 features.

  • checks (Union[Check, list[Union[Check, Hypothesis]], None]) – List of Check instances for value validation.

  • nullable (bool) – Whether the key can be missing from the TensorDict.

  • coerce (bool) – Whether to coerce dtype during validation.

  • name (Union[str, tuple[str, …], None]) – Tensor key name in TensorDict. If None, uses the key from the schema definition. May be a nested tuple key.

  • required (bool) – Whether the tensor is required (always True for now, as missing keys are handled separately).

Methods

__init__(dtype=None, shape=None, checks=None, nullable=False, coerce=False, name=None, required=True)[source]ΒΆ

Create tensor validator.

Parameters:
  • dtype (Any) – PyTorch dtype (e.g., torch.float32, torch.int64). If a string is provided, it will be converted to the corresponding torch.dtype.

  • shape (UnionType[tuple[UnionType[int, None], …], None]) – Expected shape tuple. Use None for flexible dimensions. For example, (None, 10) allows any batch size with 10 features.

  • checks (Union[Check, list[Union[Check, Hypothesis]], None]) – List of Check instances for value validation.

  • nullable (bool) – Whether the key can be missing from the TensorDict.

  • coerce (bool) – Whether to coerce dtype during validation.

  • name (Union[str, tuple[str, …], None]) – Tensor key name in TensorDict. If None, uses the key from the schema definition. May be a nested tuple key.

  • required (bool) – Whether the tensor is required (always True for now, as missing keys are handled separately).