MIT License

项目介绍

unionai-oss/pandera 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 4.5k 个 Star、504 次 Fork。

仓库全名
unionai-oss/pandera
开源许可证
MIT License
Star 数
4.5k
Fork 数
504
未关闭 Issue
383

README 摘要

The Open-source Framework for Dataset Validation 📊 🔎 ✅ Data validation for scientists, engineers, and analysts seeking correctness. 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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

pandera 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 4.5k 个 Star。

pandera 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 pandera 的源码?

可以直接克隆仓库:git clone https://github.com/unionai-oss/pandera.git,默认分支为 main;安装与运行步骤见仓库 README。

pandera 最近还在维护吗?

仓库最近一次更新为 1 天前,当前有 383 个未关闭 Issue;Star 数为 4.5k,可作为社区活跃度的参考。

README


The Open-source Framework for Dataset Validation

📊 🔎 ✅

Data validation for scientists, engineers, and analysts seeking correctness.


CI Build Documentation Status PyPI version shields.io PyPI license pyOpenSci Project Status: Active – The project has reached a stable, usable state and is being actively developed. Documentation Status codecov PyPI pyversions DOI asv Total Downloads Conda Downloads Slack

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.0 introduces the pandera.pandas module, which is now the (highly) recommended way of defining DataFrameSchemas and DataFrameModels for pandas data structures like DataFrames. Defining a dataframe schema from the top-level pandera module will produce a FutureWarning:

import pandera as pa

schema = pa.DataFrameSchema({"col": pa.Column(str)})

Update your import to:

import pandera.pandas as pa

And all of the rest of your pandera code should work. Using the top-level pandera module to access DataFrameSchema and the other pandera classes or functions will be deprecated in version 0.29.0

Next steps

See the official documentation to learn more.

评论

暂无评论