diff --git a/pandas/_typing.py b/pandas/_typing.py index 074b57054c0d1..c50d532f40dd7 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -64,6 +64,7 @@ from pandas.core.window.rolling import BaseWindow from pandas.io.formats.format import EngFormatter + from pandas.tseries.offsets import DateOffset else: # typing.final does not exist until py38 final = lambda x: x @@ -110,6 +111,7 @@ Suffixes = Tuple[str, str] Ordered = Optional[bool] JSONSerializable = Optional[Union[PythonScalar, List, Dict]] +Frequency = Union[str, "DateOffset"] Axes = Collection[Any] # dtypes diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3fe330f659513..3c872bdedbc02 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -63,6 +63,7 @@ FloatFormatType, FormattersType, FrameOrSeriesUnion, + Frequency, IndexKeyFunc, IndexLabel, Level, @@ -4678,7 +4679,11 @@ def _replace_columnwise( @doc(NDFrame.shift, klass=_shared_doc_kwargs["klass"]) def shift( - self, periods=1, freq=None, axis: Axis = 0, fill_value=lib.no_default + self, + periods=1, + freq: Optional[Frequency] = None, + axis: Axis = 0, + fill_value=lib.no_default, ) -> DataFrame: axis = self._get_axis_number(axis) @@ -9499,7 +9504,7 @@ def quantile( @doc(NDFrame.asfreq, **_shared_doc_kwargs) def asfreq( self, - freq, + freq: Frequency, method=None, how: Optional[str] = None, normalize: bool = False, @@ -9545,7 +9550,11 @@ def resample( ) def to_timestamp( - self, freq=None, how: str = "start", axis: Axis = 0, copy: bool = True + self, + freq: Optional[Frequency] = None, + how: str = "start", + axis: Axis = 0, + copy: bool = True, ) -> DataFrame: """ Cast to DatetimeIndex of timestamps, at *beginning* of period. @@ -9578,7 +9587,9 @@ def to_timestamp( setattr(new_obj, axis_name, new_ax) return new_obj - def to_period(self, freq=None, axis: Axis = 0, copy: bool = True) -> DataFrame: + def to_period( + self, freq: Optional[Frequency] = None, axis: Axis = 0, copy: bool = True + ) -> DataFrame: """ Convert DataFrame from DatetimeIndex to PeriodIndex.