Skip to content

TYP: create a Frequency alias in _typing #39919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
FloatFormatType,
FormattersType,
FrameOrSeriesUnion,
Frequency,
IndexKeyFunc,
IndexLabel,
Level,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down