I’m writing functions that act on pandas.Series
with a DateTimeIndex
. I can do type hints, like so:
import pandas as pd
def filter_year(s: pd.Series, year: int) -> pd.Series:
keep = s.index.year == year
return s[keep]
This works fine, but the editor complains Cannot access attribute "year" for class "Index"
. The reason is, that I did not specify that s
has a DateTimeIndex
.
Is there a way to do that??