From e9b40190a29aa7ba5b9b739fe04f75c6bbc340e0 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Sun, 24 Jan 2021 23:28:25 -0500 Subject: [PATCH 1/3] add DateOffset --- pandas/_typing.py | 2 ++ pandas/core/frame.py | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index 0b50dd69f7abb..0435b20447e7c 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -30,6 +30,7 @@ from typing import final from pandas._libs import Period, Timedelta, Timestamp + from pandas._libs.tslibs.offsets import DateOffset from pandas.core.dtypes.dtypes import ExtensionDtype @@ -92,6 +93,7 @@ Ordered = Optional[bool] JSONSerializable = Optional[Union[PythonScalar, List, Dict]] Axes = Collection +Frequency = Union[str, DateOffset] # dtypes NpDtype = Union[str, np.dtype] diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1d8280ae3b2f1..78f7ec47e99cf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -59,6 +59,7 @@ FloatFormatType, FormattersType, FrameOrSeriesUnion, + Frequency, IndexKeyFunc, IndexLabel, Label, @@ -4582,7 +4583,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) @@ -9371,7 +9376,7 @@ def quantile( @doc(NDFrame.asfreq, **_shared_doc_kwargs) def asfreq( self, - freq, + freq: Frequency, method=None, how: Optional[str] = None, normalize: bool = False, @@ -9417,7 +9422,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. @@ -9450,7 +9459,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. From 7b24af7472d87c29d49811548b331963d0c93022 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Fri, 19 Feb 2021 17:05:34 -0500 Subject: [PATCH 2/3] fix import --- pandas/_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index 951883d6e56b1..2c74498fb35a9 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -43,7 +43,6 @@ Timedelta, Timestamp, ) - from pandas._libs.tslibs.offsets import DateOffset from pandas.core.dtypes.dtypes import ExtensionDtype @@ -65,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 From 0fbc8995b9dfd0c659e855c40c7dbfdbbf4d1503 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Fri, 19 Feb 2021 17:22:16 -0500 Subject: [PATCH 3/3] use string quotes --- pandas/_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index 2c74498fb35a9..c50d532f40dd7 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -111,7 +111,7 @@ Suffixes = Tuple[str, str] Ordered = Optional[bool] JSONSerializable = Optional[Union[PythonScalar, List, Dict]] -Frequency = Union[str, DateOffset] +Frequency = Union[str, "DateOffset"] Axes = Collection[Any] # dtypes