Replies: 1 comment
-
https://stackoverflow.com/a/79574244/12603110 thanks to @ Viktor Dremov Pandera as of now does not support From the pandera documentation:
# schema.py
import pandera as pa
from pandera.typing import Index
class DateIndexModel(pa.DataFrameModel):
date: Index[pa.engines.pandas_engine.Date] Works and passes the mypy validation import pandas as pd
from datetime import date
from schema import DateIndexModel
data = {'value': [10, 20, 30]}
dates = [date(2024, 1, 1), date(2024, 1, 2), date(2024, 1, 3)]
df = pd.DataFrame(data, index=dates)
DateIndexModel.validate(df) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Pandera to define a schema for a pandas DataFrame where the index represents calendar dates (without time). I want to type-annotate the index as holding datetime.date values. Here's what I tried:
But running
mypy
gives the following error:I know that
datetime64[ns]
orpandas.Timestamp
work fine, but I specifically want to model just dates without time. Is there a type-safe way to do this withPandera
andmypy
?Any workaround that lets me enforce date-only index semantics (with or without
datetime.date
) while keepingmypy
happy?Colab example notebook:
https://colab.research.google.com/drive/1AdiztxHlyvEMo6B3CzYnvzlnh6a0GfUQ?usp=sharing
Beta Was this translation helpful? Give feedback.
All reactions