"Validating Complex Types Using Pydantic"
summary
Shows how to turn typing metadata into runtime checks using Pydantic: use Annotated/TypeAlias plus Pydantic’s Field and after_validator to express constraints (example: positive int and even-length string) and three validator entry points—BaseModel, a function decorator, and TypeAdapter—to validate inputs and return values. Demonstrates validating Pandas DataFrame columns and dtypes and PyTorch Tensor shapes, devices and dtypes, including a custom DS validator package that wraps Pydantic config, provides built-in torch/numpy/pandas validators, and a decorator to create reusable tensor-dimension checks that raise clear validation errors.
AI-written summary · about
chapters (7)
- 0:00Introduction
- 1:08Complex types in Python
- 7:56Type aliases for clarity
- 13:35Validating with Pydantic
- 16:25Data science validation basics
- 20:41DS Validator package
- 27:11Summary
related talks
26mIntro to Pydantic, run-time type checking for your dataclasses
28mMind the gap! Why static typing requires more than just adding annotations
31mStatic Type Analysis for Robust Data Products
22mPydantic Power-up: Performance Tips for Lightning-Fast Python Applications
32mHaving fun with pydantic and pattern matching
21mLet JSON Schema and Pydantic write your data models
57mWhy You Should Care About Types
38mMigrating existing codebases to using type annotations
