feat(pandas): add Timestamp, Series and DataFrame types (#64) - #389
Draft
MukundaKatta wants to merge 1 commit into
Draft
feat(pandas): add Timestamp, Series and DataFrame types (#64)#389MukundaKatta wants to merge 1 commit into
MukundaKatta wants to merge 1 commit into
Conversation
Adds pydantic_extra_types/pandas_types.py exposing: - Timestamp: pd.Timestamp subclass with Pydantic CoreSchema (string parsing, datetime passthrough, ISO-8601 JSON serialization, date-time JSON schema). - Series: passthrough validator with Series.to_list() JSON serialization. - DataFrame: passthrough validator with to_dict(orient='records') serialization. pandas is added as an optional dependency (project.optional-dependencies.pandas and included in the existing 'all' extra). Install with 'pip install pydantic-extra-types[pandas]'. Tests cover validation paths, error handling, JSON serialization and JSON schema generation. Closes pydantic#64.
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.
Summary
Closes #64. Adds opt-in pandas type integration. pandas is an optional dependency; importing the new module without it raises a friendly
RuntimeError.Types added (
pydantic_extra_types/pandas_types.py)Timestamp—pd.Timestampsubclass with Pydantic CoreSchema. Accepts strings, ints/floats,datetime, and existingpd.Timestamp. JSON serializes to ISO-8601, JSON schema ={type:string, format:date-time}.Series— passthrough validator (also accepts list/tuple). JSON serializes viato_list(), schema ={type:array}.DataFrame— passthrough validator (also accepts list/dict). JSON serializes viato_dict(orient='records'), schema = array-of-objects.Dependency handling
pandas is OPTIONAL via
project.optional-dependencies.pandas = ['pandas>=2']and added to theallextra. Core package deps unchanged.Files changed
pydantic_extra_types/pandas_types.py(new, 137 LOC)tests/test_pandas.py(new, 18 tests)pyproject.toml— added 2 lines for the pandas extraTest plan
ruff format+ruff checkcleantest_epoch.pystill passes (no regressions)