Skip to content

Fix inplace overload for DataFrame.interpolate #694

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 2 commits into from
May 12, 2023
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: 1 addition & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ class DataFrame(NDFrame, OpsMixin):
limit_direction: Literal["forward", "backward", "both"] = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: Literal["infer"] | None = ...,
inplace: Literal[False],
inplace: Literal[False] = ...,
**kwargs,
) -> DataFrame: ...
@overload
Expand Down
25 changes: 1 addition & 24 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -210,38 +210,15 @@ class DataFrameGroupBy(GroupBy, Generic[ByT]):
def cumsum(self, axis: Axis = ..., **kwargs) -> DataFrame: ...
def describe(self, **kwargs) -> DataFrame: ...
def ffill(self, limit: int | None = ...) -> DataFrame: ...
@overload
def fillna(
self,
value,
method: str | None = ...,
axis: Axis = ...,
limit: int | None = ...,
downcast: dict | None = ...,
*,
inplace: Literal[True],
) -> None: ...
@overload
def fillna(
self,
value,
method: str | None = ...,
axis: Axis = ...,
inplace: Literal[False] = ...,
limit: int | None = ...,
downcast: dict | None = ...,
*,
inplace: Literal[False],
) -> DataFrame: ...
@overload
def fillna(
self,
value,
method: str | None = ...,
axis: Axis = ...,
inplace: bool = ...,
limit: int | None = ...,
downcast: dict | None = ...,
) -> DataFrame | None: ...
def first(self, **kwargs) -> DataFrame: ...
def head(self, n: int = ...) -> DataFrame: ...
def hist(
Expand Down
20 changes: 20 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2695,3 +2695,23 @@ def test_to_json_mode() -> None:
check(assert_type(result4, str), str)
if TYPE_CHECKING_INVALID_USAGE:
result3 = df.to_json(orient="records", lines=False, mode="a") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues]


def test_interpolate_inplace() -> None:
# GH 691
df = pd.DataFrame({"a": range(3)})
check(assert_type(df.interpolate(method="linear"), pd.DataFrame), pd.DataFrame)
check(
assert_type(df.interpolate(method="linear", inplace=False), pd.DataFrame),
pd.DataFrame,
)
check(assert_type(df.interpolate(method="linear", inplace=True), None), type(None))


def test_groupby_fillna_inplace() -> None:
# GH 691
groupby = pd.DataFrame({"a": range(3), "b": range(3)}).groupby("a")
check(assert_type(groupby.fillna(0), pd.DataFrame), pd.DataFrame)
check(assert_type(groupby.fillna(0, inplace=False), pd.DataFrame), pd.DataFrame)
if TYPE_CHECKING_INVALID_USAGE:
groupby.fillna(0, inplace=True) # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]