feat: Introduce pydantic conversion for schemas#324
Merged
Oliver Borchert (borchero) merged 12 commits intomainfrom Apr 13, 2026
Merged
feat: Introduce pydantic conversion for schemas#324Oliver Borchert (borchero) merged 12 commits intomainfrom
Oliver Borchert (borchero) merged 12 commits intomainfrom
Conversation
Agent-Logs-Url: https://github.com/Quantco/dataframely/sessions/c7146408-7625-42bd-93a1-9681303abab7 Co-authored-by: borchero <22455425+borchero@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Quantco/dataframely/sessions/c7146408-7625-42bd-93a1-9681303abab7 Co-authored-by: borchero <22455425+borchero@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #324 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 56 56
Lines 3233 3399 +166
==========================================
+ Hits 3233 3399 +166 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
@claude[agent] implement all review comments |
Agent-Logs-Url: https://github.com/Quantco/dataframely/sessions/5299dcd4-f2fc-4862-b4b6-79fe11566ad8 Co-authored-by: borchero <22455425+borchero@users.noreply.github.com>
Member
|
@claude[agent] implement the review comment |
…eld_kwargs Agent-Logs-Url: https://github.com/Quantco/dataframely/sessions/d86654c8-ab94-47c3-a954-51d8f34341d7 Co-authored-by: borchero <22455425+borchero@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds first-class Pydantic v2 support to Dataframely schemas/columns to enable generating structured-output models (e.g., for LLM constrained decoding) directly from dy.Schema.
Changes:
- Add
Schema.to_pydantic_model()to generate apydantic.BaseModelreflecting schema columns and structured constraints. - Introduce
Column.pydantic_field()plus per-column_python_type/_pydantic_field_kwargs()implementations to translate constraints into Pydantic annotations. - Add an optionals-only test suite covering pydantic field generation and basic schema-to-model conversion.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/schema/test_pydantic_model.py | Tests for Schema.to_pydantic_model() behavior (basic fields, validation, warning on schema rules). |
| tests/columns/test_pydantic.py | Tests for Column.pydantic_field() across many column types and constraints/warnings. |
| dataframely/schema.py | Implements Schema.to_pydantic_model() using pydantic.create_model. |
| dataframely/columns/_base.py | Adds Column.pydantic_field(), _python_type abstract property, and _pydantic_field_kwargs() hook. |
| dataframely/columns/_mixins.py | Adds _pydantic_field_kwargs() to OrdinalMixin to translate min/max constraints. |
| dataframely/columns/any.py | Defines _python_type for Any to support pydantic type generation. |
| dataframely/columns/array.py | Adds _python_type and pydantic length constraints for arrays (incl. multidim warning). |
| dataframely/columns/binary.py | Defines _python_type for binary columns. |
| dataframely/columns/bool.py | Defines _python_type for bool columns. |
| dataframely/columns/categorical.py | Defines _python_type for categorical columns. |
| dataframely/columns/datetime.py | Defines _python_type and warnings for non-translatable datetime/date/time/duration constraints. |
| dataframely/columns/decimal.py | Defines _python_type and pydantic decimal-place constraint. |
| dataframely/columns/enum.py | Defines _python_type using Literal[...] for category validation. |
| dataframely/columns/float.py | Defines _python_type and pydantic constraints for bounds/inf/nan handling (incl. warning). |
| dataframely/columns/integer.py | Defines _python_type and pydantic constraints for integer bounds and is_in. |
| dataframely/columns/list.py | Defines _python_type and pydantic min/max length constraints for lists. |
| dataframely/columns/object.py | Defines _python_type for object columns. |
| dataframely/columns/string.py | Defines _python_type and pydantic length/pattern constraints for strings. |
| dataframely/columns/struct.py | Defines _python_type as an inner pydantic model for struct validation. |
Andreas Albert (AndreasAlbertQC)
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #323.
Changes
to_pydantic_modelondy.SchemaSide-note: GitHub-orchestrated Claude was really unhelpful 🫠