pandera.api.tensordict.model.TensorDictModel

class pandera.api.tensordict.model.TensorDictModel(*args: Any, **kwargs: Any)[source]

Declarative TensorDict schema using class definitions.

Fields are defined using pa.Field directly in type annotations. Use PyTorch dtypes

(e.g., torch.float32, torch.int64) to specify the expected data type:

Example:
>>> import torch
>>> import pandera.tensordict as pa
>>> class MySchema(pa.TensorDictModel):
...     observation: torch.float32 = pa.Field(shape=(None, 10))
...     action: torch.int64 = pa.Field(shape=(None,))
...
...     class Config:
...         batch_size = (32,)
>>> schema = MySchema.to_schema()

Validate data against model schema.

Methods

classmethod build_schema_(**kwargs)[source]

Create TensorDictSchema from model class.

Return type:

TensorDictSchema

Returns:

TensorDictSchema with fields converted to Tensor components.

classmethod to_schema()[source]

Create TensorDictSchema from the TensorDictModel.

Return type:

TensorDictSchema

classmethod validate(check_obj, head=None, tail=None, sample=None, random_state=None, lazy=False, inplace=False)[source]

Validate data against model schema.

Parameters:

check_obj (Any) – TensorDict or tensorclass to validate.

Return type:

Any

Returns:

Validated data object.