├── tests ├── __init__.py ├── examples.py ├── test_dummy_data.py ├── test_dtypes.py ├── test_model.py └── test_polars.py ├── src └── patito │ ├── _pydantic │ ├── __init__.py │ ├── dtypes │ │ ├── __init__.py │ │ ├── utils.py │ │ └── dtypes.py │ ├── schema.py │ ├── repr.py │ └── column_info.py │ ├── _docs.py │ ├── __init__.py │ ├── exceptions.py │ ├── validators.py │ └── polars.py ├── .tool-versions ├── docs ├── license.rst ├── api │ ├── patito │ │ ├── Field │ │ │ └── index.rst │ │ ├── Model │ │ │ ├── drop.rst │ │ │ ├── rename.rst │ │ │ ├── suffix.rst │ │ │ ├── example.rst │ │ │ ├── dtypes.rst │ │ │ ├── from_row.rst │ │ │ ├── DataFrame.rst │ │ │ ├── LazyFrame.rst │ │ │ ├── columns.rst │ │ │ ├── defaults.rst │ │ │ ├── join.rst │ │ │ ├── with_fields.rst │ │ │ ├── example_value.rst │ │ │ ├── prefix.rst │ │ │ ├── select.rst │ │ │ ├── valid_dtypes.rst │ │ │ ├── examples.rst │ │ │ ├── pandas_examples.rst │ │ │ ├── unique_columns.rst │ │ │ ├── validate.rst │ │ │ ├── nullable_columns.rst │ │ │ ├── iter_models.rst │ │ │ ├── non_nullable_columns.rst │ │ │ └── index.rst │ │ └── DataFrame │ │ │ ├── cast.rst │ │ │ ├── drop.rst │ │ │ ├── derive.rst │ │ │ ├── read_csv.rst │ │ │ ├── fill_null.rst │ │ │ ├── get.rst │ │ │ ├── validate.rst │ │ │ ├── set_model.rst │ │ │ ├── iter_models.rst │ │ │ └── index.rst │ └── index.rst ├── tutorial │ ├── index.rst │ └── dataframe-validation.rst ├── fix_header_underline.py ├── conf.py ├── index.rst └── _static │ └── css │ └── custom.css ├── .github └── workflows │ ├── ci.yml │ ├── pre-commit.yml │ ├── coverage.yml │ └── release.yml ├── .readthedocs.yaml ├── .pre-commit-config.yaml ├── LICENSE ├── noxfile.py ├── .gitignore ├── pyproject.toml └── README.md /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/patito/_pydantic/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | python 3.12.2 2 | poetry 1.8.3 3 | -------------------------------------------------------------------------------- /docs/license.rst: -------------------------------------------------------------------------------- 1 | Licence 2 | ======= 3 | 4 | .. include:: ../LICENSE 5 | -------------------------------------------------------------------------------- /docs/api/patito/Field/index.rst: -------------------------------------------------------------------------------- 1 | .. _Field: 2 | 3 | patito.Field 4 | ============ 5 | 6 | .. autofunction:: patito.Field 7 | -------------------------------------------------------------------------------- /docs/tutorial/index.rst: -------------------------------------------------------------------------------- 1 | Tutorials 2 | ========= 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | 7 | dataframe-validation 8 | -------------------------------------------------------------------------------- /docs/api/patito/Model/drop.rst: -------------------------------------------------------------------------------- 1 | patito.Model.drop 2 | ================= 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.drop 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/rename.rst: -------------------------------------------------------------------------------- 1 | patito.Model.rename 2 | =================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.rename 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/suffix.rst: -------------------------------------------------------------------------------- 1 | patito.Model.suffix 2 | =================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.suffix 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/example.rst: -------------------------------------------------------------------------------- 1 | patito.Model.example 2 | ==================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.example 7 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/cast.rst: -------------------------------------------------------------------------------- 1 | patito.DataFrame.cast 2 | ===================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: DataFrame.cast 7 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/drop.rst: -------------------------------------------------------------------------------- 1 | patito.DataFrame.drop 2 | ===================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: DataFrame.drop 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/dtypes.rst: -------------------------------------------------------------------------------- 1 | patito.Model.dtypes 2 | =================== 3 | 4 | .. currentmodule:: patito._docs 5 | 6 | .. autoproperty:: Model.dtypes 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/from_row.rst: -------------------------------------------------------------------------------- 1 | patito.Model.from_row 2 | ===================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.from_row 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/DataFrame.rst: -------------------------------------------------------------------------------- 1 | patito.Model.DataFrame 2 | ====================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.DataFrame 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/LazyFrame.rst: -------------------------------------------------------------------------------- 1 | patito.Model.LazyFrame 2 | ====================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.LazyFrame 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/columns.rst: -------------------------------------------------------------------------------- 1 | patito.Model.columns 2 | ==================== 3 | 4 | .. currentmodule:: patito._docs 5 | 6 | .. autoproperty:: Model.columns 7 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/derive.rst: -------------------------------------------------------------------------------- 1 | patito.DataFrame.derive 2 | ======================= 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: DataFrame.derive 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/defaults.rst: -------------------------------------------------------------------------------- 1 | patito.Model.defaults 2 | ===================== 3 | 4 | .. currentmodule:: patito._docs 5 | 6 | .. autoproperty:: Model.defaults 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/join.rst: -------------------------------------------------------------------------------- 1 | .. _Model.join: 2 | 3 | patito.Model.join 4 | ================= 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: Model.join 9 | -------------------------------------------------------------------------------- /docs/api/patito/Model/with_fields.rst: -------------------------------------------------------------------------------- 1 | patito.Model.with_fields 2 | ======================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.with_fields 7 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/read_csv.rst: -------------------------------------------------------------------------------- 1 | patito.DataFrame.read_csv 2 | ========================= 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: DataFrame.read_csv 7 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/fill_null.rst: -------------------------------------------------------------------------------- 1 | patito.DataFrame.fill_null 2 | ========================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: DataFrame.fill_null 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/example_value.rst: -------------------------------------------------------------------------------- 1 | patito.Model.example_value 2 | ========================== 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.example_value 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/prefix.rst: -------------------------------------------------------------------------------- 1 | .. _Model.prefix: 2 | 3 | patito.Model.prefix 4 | =================== 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: Model.prefix 9 | -------------------------------------------------------------------------------- /docs/api/patito/Model/select.rst: -------------------------------------------------------------------------------- 1 | .. _Model.select: 2 | 3 | patito.Model.select 4 | =================== 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: Model.select 9 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/get.rst: -------------------------------------------------------------------------------- 1 | .. _DataFrame.get: 2 | 3 | patito.DataFrame.get 4 | ==================== 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: DataFrame.get 9 | -------------------------------------------------------------------------------- /docs/api/patito/Model/valid_dtypes.rst: -------------------------------------------------------------------------------- 1 | patito.Model.valid_dtypes 2 | ========================= 3 | 4 | .. currentmodule:: patito._docs 5 | 6 | .. autoproperty:: Model.valid_dtypes 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/examples.rst: -------------------------------------------------------------------------------- 1 | .. _Model.examples: 2 | 3 | patito.Model.examples 4 | ===================== 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: Model.examples 9 | -------------------------------------------------------------------------------- /docs/api/patito/Model/pandas_examples.rst: -------------------------------------------------------------------------------- 1 | patito.Model.pandas_examples 2 | ============================ 3 | 4 | .. currentmodule:: patito 5 | 6 | .. automethod:: Model.pandas_examples 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/unique_columns.rst: -------------------------------------------------------------------------------- 1 | patito.Model.unique_columns 2 | =========================== 3 | 4 | .. currentmodule:: patito._docs 5 | 6 | .. autoproperty:: Model.unique_columns 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/validate.rst: -------------------------------------------------------------------------------- 1 | .. _Model.validate: 2 | 3 | patito.Model.validate 4 | ===================== 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: Model.validate 9 | -------------------------------------------------------------------------------- /src/patito/_docs.py: -------------------------------------------------------------------------------- 1 | """Ugly workaround for Sphinx + autodoc + ModelMetaclass + classproperty.""" 2 | 3 | from patito.pydantic import ModelMetaclass as Model # noqa: F401, pragma: no cover 4 | -------------------------------------------------------------------------------- /docs/api/patito/Model/nullable_columns.rst: -------------------------------------------------------------------------------- 1 | patito.Model.nullable_columns 2 | ============================= 3 | 4 | .. currentmodule:: patito._docs 5 | 6 | .. autoproperty:: Model.nullable_columns 7 | -------------------------------------------------------------------------------- /docs/api/patito/Model/iter_models.rst: -------------------------------------------------------------------------------- 1 | .. _Model.iter_models: 2 | 3 | patito.Model.iter_models 4 | ======================== 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: Model.iter_models 9 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/validate.rst: -------------------------------------------------------------------------------- 1 | .. _DataFrame.validate: 2 | 3 | patito.DataFrame.validate 4 | ========================= 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: DataFrame.validate 9 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/set_model.rst: -------------------------------------------------------------------------------- 1 | .. _DataFrame.set_model: 2 | 3 | patito.DataFrame.set_model 4 | ========================== 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: DataFrame.set_model 9 | -------------------------------------------------------------------------------- /docs/api/patito/Model/non_nullable_columns.rst: -------------------------------------------------------------------------------- 1 | patito.Model.non_nullable_columns 2 | ================================= 3 | 4 | .. currentmodule:: patito._docs 5 | 6 | .. autoproperty:: Model.non_nullable_columns 7 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/iter_models.rst: -------------------------------------------------------------------------------- 1 | .. _DataFrame.iter_models: 2 | 3 | patito.DataFrame.iter_models 4 | ============================ 5 | 6 | .. currentmodule:: patito 7 | 8 | .. automethod:: DataFrame.iter_models 9 | -------------------------------------------------------------------------------- /docs/api/index.rst: -------------------------------------------------------------------------------- 1 | API Reference 2 | ============= 3 | 4 | .. toctree:: 5 | :caption: General Functionality 6 | :maxdepth: 1 7 | 8 | patito/DataFrame/index 9 | patito/Model/index 10 | patito/Field/index 11 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: push 3 | jobs: 4 | tests: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - name: Install uv 9 | uses: astral-sh/setup-uv@v5 10 | - run: uv run nox 11 | -------------------------------------------------------------------------------- /.github/workflows/pre-commit.yml: -------------------------------------------------------------------------------- 1 | name: pre-commit 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [main] 7 | 8 | jobs: 9 | pre-commit: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | - uses: actions/setup-python@v5 14 | - uses: pre-commit/action@v3.0.1 15 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: Coverage 2 | on: 3 | pull_request: 4 | push: 5 | branches: [main] 6 | 7 | jobs: 8 | coverage: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Install uv 13 | uses: astral-sh/setup-uv@v5 14 | - run: uv run nox --sessions test-3.9 15 | env: 16 | CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} 17 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | python: 4 | install: 5 | - method: pip 6 | path: . 7 | extra_requirements: 8 | - pandas 9 | - docs 10 | 11 | build: 12 | os: ubuntu-22.04 13 | tools: 14 | python: "3.10" 15 | 16 | sphinx: 17 | configuration: docs/conf.py 18 | # TODO: Set to true once patito.Field autodoc works with unicode type annotation 19 | fail_on_warning: false 20 | 21 | formats: all 22 | -------------------------------------------------------------------------------- /docs/api/patito/DataFrame/index.rst: -------------------------------------------------------------------------------- 1 | patito.DataFrame 2 | ================ 3 | 4 | .. currentmodule:: patito 5 | 6 | .. autoclass:: DataFrame 7 | 8 | .. toctree:: 9 | :caption: Methods 10 | :maxdepth: 1 11 | 12 | cast 13 | derive 14 | drop 15 | fill_null 16 | get 17 | iter_models 18 | read_csv 19 | set_model 20 | validate 21 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v4.5.0 4 | hooks: 5 | - id: check-yaml 6 | - id: end-of-file-fixer 7 | - id: trailing-whitespace 8 | - repo: https://github.com/astral-sh/ruff-pre-commit 9 | # Ruff version. 10 | rev: v0.7.0 11 | hooks: 12 | # Run the linter. 13 | - id: ruff 14 | args: [ --fix ] 15 | # Run the formatter. 16 | - id: ruff-format 17 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | release: 4 | types: [published] 5 | jobs: 6 | release: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: actions/setup-python@v5 11 | with: 12 | python-version: | 13 | 3.9 14 | 3.10 15 | 3.11 16 | 3.12 17 | architecture: x64 18 | - name: Install uv 19 | uses: astral-sh/setup-uv@v5 20 | - run: uv run nox 21 | - run: uv build 22 | - run: uv publish --username=__token__ --password=${{ secrets.PYPI_TOKEN }} 23 | -------------------------------------------------------------------------------- /docs/fix_header_underline.py: -------------------------------------------------------------------------------- 1 | """A simple script to fix RST headers.""" 2 | 3 | import sys 4 | from pathlib import Path 5 | 6 | if __name__ == "__main__": 7 | arguments = sys.argv 8 | directory = Path(arguments[1]) 9 | 10 | for file in directory.rglob("*.rst"): 11 | lines = [] 12 | for line_number, line in enumerate(file.read_text().splitlines()): 13 | if line.startswith("===="): 14 | header_length = len(lines[line_number - 1]) 15 | lines.append("=" * header_length) 16 | else: 17 | lines.append(line) 18 | file.write_text("\n".join(lines) + "\n") 19 | -------------------------------------------------------------------------------- /src/patito/_pydantic/dtypes/__init__.py: -------------------------------------------------------------------------------- 1 | from patito._pydantic.dtypes.dtypes import ( 2 | DtypeResolver, 3 | default_dtypes_for_model, 4 | valid_dtypes_for_model, 5 | validate_annotation, 6 | validate_polars_dtype, 7 | ) 8 | from patito._pydantic.dtypes.utils import ( 9 | PYTHON_TO_PYDANTIC_TYPES, 10 | dtype_from_string, 11 | is_optional, 12 | parse_composite_dtype, 13 | ) 14 | 15 | __all__ = [ 16 | "DtypeResolver", 17 | "validate_annotation", 18 | "validate_polars_dtype", 19 | "parse_composite_dtype", 20 | "dtype_from_string", 21 | "valid_dtypes_for_model", 22 | "default_dtypes_for_model", 23 | "PYTHON_TO_PYDANTIC_TYPES", 24 | "is_optional", 25 | ] 26 | -------------------------------------------------------------------------------- /docs/api/patito/Model/index.rst: -------------------------------------------------------------------------------- 1 | .. _Model: 2 | 3 | patito.Model 4 | ============ 5 | 6 | .. currentmodule:: patito 7 | 8 | .. autoclass:: Model 9 | 10 | .. toctree:: 11 | :caption: Class methods & properties 12 | :maxdepth: 1 13 | 14 | DataFrame 15 | LazyFrame 16 | columns 17 | defaults 18 | drop 19 | dtypes 20 | example 21 | example_value 22 | examples 23 | from_row 24 | iter_models 25 | join 26 | non_nullable_columns 27 | nullable_columns 28 | pandas_examples 29 | prefix 30 | rename 31 | select