Skip to content

Commit 6e243b6

Browse files
authored
TYP: create a Frequency alias in _typing (#39919)
1 parent 6f8ae81 commit 6e243b6

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pandas/_typing.py

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from pandas.core.window.rolling import BaseWindow
6565

6666
from pandas.io.formats.format import EngFormatter
67+
from pandas.tseries.offsets import DateOffset
6768
else:
6869
# typing.final does not exist until py38
6970
final = lambda x: x
@@ -110,6 +111,7 @@
110111
Suffixes = Tuple[str, str]
111112
Ordered = Optional[bool]
112113
JSONSerializable = Optional[Union[PythonScalar, List, Dict]]
114+
Frequency = Union[str, "DateOffset"]
113115
Axes = Collection[Any]
114116

115117
# dtypes

pandas/core/frame.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
FloatFormatType,
6464
FormattersType,
6565
FrameOrSeriesUnion,
66+
Frequency,
6667
IndexKeyFunc,
6768
IndexLabel,
6869
Level,
@@ -4678,7 +4679,11 @@ def _replace_columnwise(
46784679

46794680
@doc(NDFrame.shift, klass=_shared_doc_kwargs["klass"])
46804681
def shift(
4681-
self, periods=1, freq=None, axis: Axis = 0, fill_value=lib.no_default
4682+
self,
4683+
periods=1,
4684+
freq: Optional[Frequency] = None,
4685+
axis: Axis = 0,
4686+
fill_value=lib.no_default,
46824687
) -> DataFrame:
46834688
axis = self._get_axis_number(axis)
46844689

@@ -9476,7 +9481,7 @@ def quantile(
94769481
@doc(NDFrame.asfreq, **_shared_doc_kwargs)
94779482
def asfreq(
94789483
self,
9479-
freq,
9484+
freq: Frequency,
94809485
method=None,
94819486
how: Optional[str] = None,
94829487
normalize: bool = False,
@@ -9522,7 +9527,11 @@ def resample(
95229527
)
95239528

95249529
def to_timestamp(
9525-
self, freq=None, how: str = "start", axis: Axis = 0, copy: bool = True
9530+
self,
9531+
freq: Optional[Frequency] = None,
9532+
how: str = "start",
9533+
axis: Axis = 0,
9534+
copy: bool = True,
95269535
) -> DataFrame:
95279536
"""
95289537
Cast to DatetimeIndex of timestamps, at *beginning* of period.
@@ -9555,7 +9564,9 @@ def to_timestamp(
95559564
setattr(new_obj, axis_name, new_ax)
95569565
return new_obj
95579566

9558-
def to_period(self, freq=None, axis: Axis = 0, copy: bool = True) -> DataFrame:
9567+
def to_period(
9568+
self, freq: Optional[Frequency] = None, axis: Axis = 0, copy: bool = True
9569+
) -> DataFrame:
95599570
"""
95609571
Convert DataFrame from DatetimeIndex to PeriodIndex.
95619572

0 commit comments

Comments
 (0)