Skip to content

GH1169 Improve parameter types for DataFrame.pct_change and Series.pct_change #1194

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 7 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
15 changes: 8 additions & 7 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ from pandas._libs.lib import NoDefault
from pandas._libs.missing import NAType
from pandas._libs.tslibs import BaseOffset
from pandas._libs.tslibs.nattype import NaTType
from pandas._libs.tslibs.offsets import DateOffset
from pandas._typing import (
S1,
AggFuncTypeBase,
Expand All @@ -87,7 +88,6 @@ from pandas._typing import (
FilePath,
FillnaOptions,
FormattersType,
Frequency,
GroupByObjectNonScalar,
HashableT,
HashableT1,
Expand Down Expand Up @@ -830,10 +830,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
) -> Self: ...
def shift(
self,
periods: int = ...,
freq: Frequency | dt.timedelta | None = ...,
periods: int | Sequence[int] = ...,
freq: DateOffset | dt.timedelta | _str | None = ...,
axis: Axis = ...,
fill_value: Hashable | None = ...,
fill_value: Scalar | NAType | None = ...,
) -> Self: ...
@overload
def set_index(
Expand Down Expand Up @@ -1989,9 +1989,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
periods: int = ...,
fill_method: None = ...,
limit: int | None = ...,
freq=...,
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1169
freq: DateOffset | dt.timedelta | _str | None = ...,
*,
axis: Axis = ...,
fill_value: Scalar | NAType | None = ...,
) -> Self: ...
def pop(self, item: _str) -> Series: ...
def pow(
Expand Down
18 changes: 9 additions & 9 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ from pandas._libs.lib import NoDefault
from pandas._libs.missing import NAType
from pandas._libs.tslibs import BaseOffset
from pandas._libs.tslibs.nattype import NaTType
from pandas._libs.tslibs.offsets import DateOffset
from pandas._typing import (
S1,
S2,
Expand All @@ -125,7 +126,6 @@ from pandas._typing import (
FilePath,
FillnaOptions,
FloatDtypeArg,
Frequency,
GroupByObjectNonScalar,
HashableT1,
IgnoreRaise,
Expand Down Expand Up @@ -1130,10 +1130,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
) -> Series[S1]: ...
def shift(
self,
periods: int = ...,
freq: Frequency | timedelta | None = ...,
axis: AxisIndex = ...,
fill_value: object | None = ...,
periods: int | Sequence[int] = ...,
freq: DateOffset | timedelta | _str | None = ...,
axis: Axis = ...,
fill_value: Scalar | NAType | None = ...,
) -> UnknownSeries: ...
def info(
self,
Expand Down Expand Up @@ -1549,10 +1549,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
def pct_change(
self,
periods: int = ...,
fill_method: _str = ...,
limit: int | None = ...,
freq=...,
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1169
fill_method: None = ...,
freq: DateOffset | timedelta | _str | None = ...,
*,
fill_value: Scalar | NAType | None = ...,
) -> Series[S1]: ...
def first_valid_index(self) -> Scalar: ...
def last_valid_index(self) -> Scalar: ...
Expand Down
3 changes: 3 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,10 @@ def test_groupby_series_methods() -> None:

def test_dataframe_pct_change() -> None:
df = pd.DataFrame({"x": [1, 2, 2, 3, 3], "y": [10, 20, 30, 40, 50]})
df.pct_change()
df.pct_change(fill_method=None)
df.pct_change(axis="columns", periods=-1)
df.pct_change(fill_value=0)


def test_indexslice_setitem():
Expand Down