v0.24.0 起需改用 import pandera.pandas as pa,顶层 pandera 导入会触发 FutureWarning 并在 0.29.0 废弃;必须安装对应后端 extra(如 pandera[pandas]),否则无法校验该类型数据;decisions 解析需配置 provider,示例中的 MockProvider 仅用于演示
pandera
unionai-ossMIT活跃维护轻量灵活的数据校验库,用声明式 schema 给 pandas 等 DataFrame 做类型、范围和统计假设检查,在数据清洗和管道里提前拦住脏数据。
A light-weight, flexible, and expressive statistical data testing library
pip install 'pandera[pandas]'README 未说明,纯 Python 库,无 GPU 或显存要求
轻量灵活的数据校验库,给 DataFrame 类数据加统计类型约束,让处理管道更可读更健壮
轻量灵活的数据校验库,用声明式 schema 给 pandas 等 DataFrame 做类型、范围和统计假设检查,在数据清洗和管道里提前拦住脏数据。
核心能力
- 用 DataFrameSchema 或 DataFrameModel 声明式定义列类型与校验规则
- 内置 Check 组合类型、范围、集合与自定义 lambda 校验
- 支持 pandas、polars、pyspark 等多种 DataFrame 库
- 用 ParsedField 从其他列派生新列,解析与校验合一
- decisions API 可调用决策模型从非结构化文本填充类型化列
容易踩的坑
- v0.35.0最新正式版2026-10-25 · 2026-10-25 02:32 UTC
⭐️ Highlights
Pandera now supports DataFusion schemas
import pyarrow from datafusion import SessionContext import pandera.datafusion as pa schema = pa.DataFrameSchema( { "state": pa.Column(str), "city": pa.Column(str), "price": pa.Column(int, pa.Check.in_range(5, 20)), } ) ctx = SessionContext() df = ctx.from_arrow( pyarrow.table( { "state": ["FL", "FL", "CA", "CA"], "city": ["Orlando", "Miami", "Los Angeles", "San Francisco"], "price": [8, 12, 10, 16], } ) ) schema.validate(df)And of course the class-based dataframe models as well:
class Schema(pa.DataFrameModel): state: str city: str price: int = pa.Field(in_range={"min_value": 5, "max_value": 20}) Schema.validate(df)What's Changed
- ci: fix path-filter quantifier so docs-only PRs skip unit tests by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2545
- fix: propagate nested Column drop_invalid_rows without mutation by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2551
- fix(io): read parametrized polars dtypes back from yaml/json by @aminmiral in https://github.com/unionai-oss/pandera/pull/2523
- fix(polars,ibis): ignore nulls in unique_values_eq by @MohammadHijjawi97 in https://github.com/unionai-oss/pandera/pull/2538
- spec: pluggable data synthesis backends (realistic data generation) by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2557
- docs(spec): apply review fixes to pluggable data synthesis proposal by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2561
- feat(tensordict): nested keys, element-level check errors, field custom checks, and @check_types integration by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2560
- fix(io): serialize MultiIndex options so they survive yaml/json/script round trips by @owgreen-dev in https://github.com/unionai-oss/pandera/pull/2504
- feat(datafusion): add datafusion.DataFrame schema validation via the narwhals-datafusion plugin by @s5dsn-eqee in https://github.com/unionai-oss/pandera/pull/2540
- fix(pandas): carry Column default through schema serialization by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2528
- fix(decorators): forward validation options to the positional obj_getter selector by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2499
- fix(checks): reject conflicting length arguments in Check.str_length by @yang00333 in https://github.com/unionai-oss/pandera/pull/2564
- fix(narwhals): resolve six datafusion xfails in the shared backend by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2562
- test(polars): reset only polars entries in the shared backend registry by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2502
- docs(tensordict): make failure-case example self-contained so docs build passes by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2569
- fix(polars): coerce to Decimal without a Float64 round trip by @DG47 in https://github.com/unionai-oss/pandera/pull/2574
- fix(pandas): carry report_duplicates and index default through serialization by @aminmiral in https://github.com/unionai-oss/pandera/pull/2573
- docs(contributing): point the Sphinx RST link at the current primer by @Yi-111-a in https://github.com/unionai-oss/pandera/pull/2571
- fix(io): serialize set check statistics such as unique_values_eq by @LuisFigueroaG in https://github.com/unionai-oss/pandera/pull/2591
- fix(tests): suppress large_base_example health check in hypothesis profiles by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2593
- fix(dask): validate Series indexes by @ska2704 in https://github.com/unionai-oss/pandera/pull/2596
- fix(polars): report a schema error for a non-decimal column by @atharva-mashalkar in https://github.com/unionai-oss/pandera/pull
- v0.34.12026-10-06 · 2026-10-06 15:15 UTC
查看更新说明
What's Changed
- Add spec for generic dataframe-agnostic schema API by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2401
- docs: announce PyTorch TensorDict support in the docs banner by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2544
Full Changelog: https://github.com/unionai-oss/pandera/compare/v0.34.0...v0.34.1
- v0.34.02026-10-05 · 2026-10-05 14:34 UTC
查看更新说明
⭐️ Highlights
This release adds TensorDict as a supported data container that can be validated with pandera:
import torch from tensordict import TensorDict import pandera.tensordict as pa schema = pa.TensorDictSchema( keys={ "observation": pa.Tensor(dtype=torch.float32, shape=(None, 10)), "action": pa.Tensor(dtype=torch.float32, shape=(None, 5)), }, batch_size=(32,), ) td = TensorDict( {"observation": torch.randn(32, 10), "action": torch.randn(32, 5)}, batch_size=[32], ) schema.validate(td)Or using a class-based model:
class RL(pa.TensorDictModel): """Schema for reinforcement learning data.""" # Use PyTorch dtypes in type annotations observation: torch.float32 = pa.Field(shape=(None, 10)) action: torch.int64 = pa.Field(shape=(None,)) reward: torch.float32 = pa.Field() class Config: batch_size = (32,) # Validate using the model - schema is built automatically td = TensorDict( {"observation": torch.randn(32, 10), "action": torch.randint(0, 4, (32,)), "reward": torch.randn(32)}, batch_size=[32], ) RL.validate(td)What's Changed
- feat(polars): add support for nested DataFrameModel validation by @Nikhil-jaiswal007 in https://github.com/unionai-oss/pandera/pull/2439
- ci: always run linters, regardless of changed paths by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2462
- docs: add a "Backward Compatibility" section to AGENTS.md by @Dev-iL in https://github.com/unionai-oss/pandera/pull/2461
- fix(api): raise informative TypeError for non-dataframe validate() input by @cognis-digital in https://github.com/unionai-oss/pandera/pull/2421
- Reject reversed bounds in Check.str_length by @chiruu12 in https://github.com/unionai-oss/pandera/pull/2476
- fix(polars): fail loudly on user-declared parsers instead of skipping them by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2473
- fix(polars): honour ignore_na=False when the check output is null by @ebarkhordar in https://github.com/unionai-oss/pandera/pull/2471
- fix(config): coerce a string validation_depth instead of silently disabling gating by @shashvat-singham in https://github.com/unionai-oss/pandera/pull/2470
- docs: clarify parser and check execution order (#2045) by @IshanA2007 in https://github.com/unionai-oss/pandera/pull/2466
- Fix documented default for DataFrameSchema.reset_index drop by @VenishPaneliya in https://github.com/unionai-oss/pandera/pull/2465
- Report integer coercion overflow instead of wrapping silently by @shashvat-singham in https://github.com/unionai-oss/pandera/pull/2443
- fix: correct get_metadata return annotations by @Gagandeep-2003 in https://github.com/unionai-oss/pandera/pull/2424
- Fix implicit Optional on Column dtype in the Ibis backend by @VenishPaneliya in https://github.com/unionai-oss/pandera/pull/2474
- fix(polars): pass parser_output on Category.try_coerce's ParserError so lazy validation reports failure cases instead of crashing by @AmirF194 in https://github.com/unionai-oss/pandera/pull/2469
- fix(polars): do not select absent optional columns when adding missin… by @Moandco in https://github.com/unionai-oss/pandera/pull/2460
- fix(polars): add missing columns with string defaults as literals (#2463) by @Moandco in https://github.com/unionai-oss/pandera/pull/2464
- fix(pandas): match tz-aware datetime dtypes that render identically (#1839) by @cycsmail in https://github.com/unionai-oss/pandera/pull/2416
- docs: derived columns + System One (Jev) parsing proposal by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2508
- fix(io): keep renamed built-in checks in serialized schemas by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2501
- Add PyTorch TensorDict validation backend by @cosmicbboy in https://github.com/unionai-oss/pandera/pull/2403
- fix: pass
- v0.33.12026-09-01 · 2026-09-01 15:20 UTC
查看更新说明
What's Changed
- docs: announce Pandera CLI and PyArrow support in banner by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2456
- fix: restore optional-column semantics for bare
T | Noneannotations by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2458 - Warn when optional columns are missing via on_missing option by @ChrisJr404 in https://github.com/unionai-oss/pandera/pull/2447
- ci: add actionlint workflow and pre-commit hook by @chernojagne in https://github.com/unionai-oss/pandera/pull/2436
New Contributors
- @ChrisJr404 made their first contribution in https://github.com/unionai-oss/pandera/pull/2447
- @chernojagne made their first contribution in https://github.com/unionai-oss/pandera/pull/2436
Full Changelog: https://github.com/unionai-oss/pandera/compare/v0.33.0...v0.33.1
- v0.33.0v0.33.0: Introducing `pandera` CLI, support pyarrow table2026-08-30 · 2026-08-30 04:16 UTC
查看更新说明
What's Changed
- Report all missing required columns in lazy validation by @vineethsaivs in https://github.com/unionai-oss/pandera/pull/2397
- fix(pandas): report differing categories in dtype mismatch error by @sha-sta in https://github.com/unionai-oss/pandera/pull/2391
- fix(pandas-engine): treat an Enum annotation as a categorical dtype (#2052) by @cycsmail in https://github.com/unionai-oss/pandera/pull/2399
- fix(pandas): run column parsers before dataframe-level coercion by @sha-sta in https://github.com/unionai-oss/pandera/pull/2400
- fix(pandas): treat NA as coercible for masked nullable dtypes by @sha-sta in https://github.com/unionai-oss/pandera/pull/2404
- Fix parenthesized @dataframe_parser() decorator form by @vineethsaivs in https://github.com/unionai-oss/pandera/pull/2408
- fix(polars): avoid concat deprecation in lazy validation by @RedZapdos123 in https://github.com/unionai-oss/pandera/pull/2411
- fix: Repair coerce and parser options for xarray Datasets by @abaarsma in https://github.com/unionai-oss/pandera/pull/2413
- feat(narwhals): support the pandas schema API in the narwhals backend by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2417
- fix(io): deserialize parametrized Decimal dtypes from yaml/json by @cycsmail in https://github.com/unionai-oss/pandera/pull/2434
- fix(pandas): apply parsers to Index fields and schema components by @cycsmail in https://github.com/unionai-oss/pandera/pull/2435
- feat(pyarrow): add first-class pyarrow.Table schema validation by @sravankumarkunadi in https://github.com/unionai-oss/pandera/pull/2427
- Add a pandera CLI: validate, infer, and generate commands by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2402
- add backend info to the cli by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2446
- fix(pandas): respect Optional pydantic fields as nullable in PydanticModel columns (closes #2406) by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2429
- doc: Fix "list" type annotation by @VeckoTheGecko in https://github.com/unionai-oss/pandera/pull/2440
- Support itemsize-parameterized numpy dtypes in the pandas engine by @mannemkarthik010 in https://github.com/unionai-oss/pandera/pull/2437
- fix: bind self correctly in check_input when an arg is passed by keyword by @Sanjays2402 in https://github.com/unionai-oss/pandera/pull/2428
- fix(polars): raise minimum polars version to
1.20.0by @fhoehle in https://github.com/unionai-oss/pandera/pull/2412 - docs: fix duplicated "the" typos in Check and Hypothesis docstrings by @maupatel in https://github.com/unionai-oss/pandera/pull/2445
- Add a backend-neutral
FieldType[T]typing contract by @Dev-iL in https://github.com/unionai-oss/pandera/pull/2448 - fix: handle scalar groupby keys in _format_groupby_input by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2420
- fix(decorators): support keyword-only / variadic functions in check_input by @feiiiiii5 in https://github.com/unionai-oss/pandera/pull/2454
- ci: only run unit tests for changed areas by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2450
- fix(docs): make intersphinx fetch resilient to transient failures by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2452
- fix(docs): scope pyspark JDK24 security-manager opt-in to JDK 24 only by @cosmicBboy in https://github.com/unionai-oss/pandera/pull/2451
- fix: respect pydantic serialization aliases by @mameikagou in https://github.com/unionai-oss/pandera/pull/2449
New Contributors
- @sha-sta made their first contribution in https://github.com/unionai-oss/pandera/pull/2391
- @abaarsma made their first contribution in https://github.com/unionai-oss/pandera/pull/2413
- @sravankumarkunadi made their first contribution in https://github.com/unionai-oss/pandera/pull/2427
- @feiiiiii5 made their first contribution in https://github.com/unionai-oss/pandera/pull/2429
- @VeckoTheGecko made their first contribution in h
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Pandera is a Union.ai open source project that provides a flexible and expressive API for performing data validation on dataframe-like objects. The goal of Pandera is to make data processing pipelines more readable and robust with statistically typed dataframes.
Install
Pandera supports multiple dataframe libraries, including pandas, polars, pyspark, and more. To validate pandas DataFrames, install Pandera with the pandas extra:
With pip:
pip install 'pandera[pandas]'
With uv:
uv pip install 'pandera[pandas]'
With conda:
conda install -c conda-forge pandera-pandas
Get started
First, create a dataframe:
import pandas as pd
import pandera.pandas as pa
# data to validate
df = pd.DataFrame({
"column1": [1, 2, 3],
"column2": [1.1, 1.2, 1.3],
"column3": ["a", "b", "c"],
})
Validate the data using the object-based API:
# define a schema
schema = pa.DataFrameSchema({
"column1": pa.Column(int, pa.Check.ge(0)),
"column2": pa.Column(float, pa.Check.lt(10)),
"column3": pa.Column(
str,
[
pa.Check.isin([*"abc"]),
pa.Check(lambda series: series.str.len() == 1),
]
),
})
print(schema.validate(df))
# column1 column2 column3
# 0 1 1.1 a
# 1 2 1.2 b
# 2 3 1.3 c
Or validate the data using the class-based API:
# define a schema
class Schema(pa.DataFrameModel):
column1: int = pa.Field(ge=0)
column2: float = pa.Field(lt=10)
column3: str = pa.Field(isin=[*"abc"])
@pa.check("column3")
def custom_check(cls, series: pd.Series) -> pd.Series:
return series.str.len() == 1
print(Schema.validate(df))
# column1 column2 column3
# 0 1 1.1 a
# 1 2 1.2 b
# 2 3 1.3 c
Parse and validate unstructured data
Pandera can derive a column from the rest of the dataframe, so a schema both
parses and validates your data. Declare the derivation on the column itself
with ParsedField
/ ParsedColumn,
and the decisions API
to fill typed columns from unstructured text by asking a decision model:
import pandera.decisions as decisions
class Tickets(pa.DataFrameModel):
body: str
n_words: int = pa.ParsedField(
parser=lambda s: s.str.split().str.len(),
source="body",
)
department: Department = pa.ParsedField(
description="Which team should handle this ticket",
parser=decisions.Choice(),
)
class Config:
parser_source = "body"
# configure a provider (MockProvider is deterministic and free; swap in a
# real model like TypeSafe Jev or an Ollaya model as a runtime setting)
with decisions.provider(decisions.MockProvider(seed=7)):
Tickets.validate(df)
See the decision parsing tutorial to get started.
[!WARNING] Pandera
v0.24.0introduces thepandera.pandasmodule, which is now the (highly) recommended way of definingDataFrameSchemas andDataFrameModels forpandasdata structures likeDataFrames. Defining a dataframe schema from the top-levelpanderamodule will produce aFutureWarning:import pandera as pa schema = pa.DataFrameSchema({"col": pa.Column(str)})Update your import to:
import pandera.pandas as paAnd all of the rest of your pandera code should work. Using the top-level
panderamodule to accessDataFrameSchemaand the other pandera classes or functions will be deprecated in version0.29.0
Next steps
See the official documentation to learn more.