Skip to content

feat(pandas): add Timestamp, Series and DataFrame types (#64) - #389

Draft
MukundaKatta wants to merge 1 commit into
pydantic:mainfrom
MukundaKatta:feat/pandas-types
Draft

feat(pandas): add Timestamp, Series and DataFrame types (#64)#389
MukundaKatta wants to merge 1 commit into
pydantic:mainfrom
MukundaKatta:feat/pandas-types

Conversation

@MukundaKatta

Copy link
Copy Markdown

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)

  • Timestamppd.Timestamp subclass with Pydantic CoreSchema. Accepts strings, ints/floats, datetime, and existing pd.Timestamp. JSON serializes to ISO-8601, JSON schema = {type:string, format:date-time}.
  • Series — passthrough validator (also accepts list/tuple). JSON serializes via to_list(), schema = {type:array}.
  • DataFrame — passthrough validator (also accepts list/dict). JSON serializes via to_dict(orient='records'), schema = array-of-objects.

Dependency handling

pandas is OPTIONAL via project.optional-dependencies.pandas = ['pandas>=2'] and added to the all extra. 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 extra

Test plan

  • ruff format + ruff check clean
  • All 18 pandas tests pass
  • Existing test_epoch.py still passes (no regressions)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support pandas types

1 participant