Skip to content

Commit 55546cf

Browse files
authored
Fix inplace overload for DataFrame.interpolate (#694)
* Fix inplace overload for DataFrame.interpolate * fix order
1 parent 5d41bcd commit 55546cf

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ class DataFrame(NDFrame, OpsMixin):
17081708
limit_direction: Literal["forward", "backward", "both"] = ...,
17091709
limit_area: Literal["inside", "outside"] | None = ...,
17101710
downcast: Literal["infer"] | None = ...,
1711-
inplace: Literal[False],
1711+
inplace: Literal[False] = ...,
17121712
**kwargs,
17131713
) -> DataFrame: ...
17141714
@overload

pandas-stubs/core/groupby/generic.pyi

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -210,38 +210,15 @@ class DataFrameGroupBy(GroupBy, Generic[ByT]):
210210
def cumsum(self, axis: Axis = ..., **kwargs) -> DataFrame: ...
211211
def describe(self, **kwargs) -> DataFrame: ...
212212
def ffill(self, limit: int | None = ...) -> DataFrame: ...
213-
@overload
214-
def fillna(
215-
self,
216-
value,
217-
method: str | None = ...,
218-
axis: Axis = ...,
219-
limit: int | None = ...,
220-
downcast: dict | None = ...,
221-
*,
222-
inplace: Literal[True],
223-
) -> None: ...
224-
@overload
225213
def fillna(
226214
self,
227215
value,
228216
method: str | None = ...,
229217
axis: Axis = ...,
218+
inplace: Literal[False] = ...,
230219
limit: int | None = ...,
231220
downcast: dict | None = ...,
232-
*,
233-
inplace: Literal[False],
234221
) -> DataFrame: ...
235-
@overload
236-
def fillna(
237-
self,
238-
value,
239-
method: str | None = ...,
240-
axis: Axis = ...,
241-
inplace: bool = ...,
242-
limit: int | None = ...,
243-
downcast: dict | None = ...,
244-
) -> DataFrame | None: ...
245222
def first(self, **kwargs) -> DataFrame: ...
246223
def head(self, n: int = ...) -> DataFrame: ...
247224
def hist(

tests/test_frame.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,3 +2695,23 @@ def test_to_json_mode() -> None:
26952695
check(assert_type(result4, str), str)
26962696
if TYPE_CHECKING_INVALID_USAGE:
26972697
result3 = df.to_json(orient="records", lines=False, mode="a") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues]
2698+
2699+
2700+
def test_interpolate_inplace() -> None:
2701+
# GH 691
2702+
df = pd.DataFrame({"a": range(3)})
2703+
check(assert_type(df.interpolate(method="linear"), pd.DataFrame), pd.DataFrame)
2704+
check(
2705+
assert_type(df.interpolate(method="linear", inplace=False), pd.DataFrame),
2706+
pd.DataFrame,
2707+
)
2708+
check(assert_type(df.interpolate(method="linear", inplace=True), None), type(None))
2709+
2710+
2711+
def test_groupby_fillna_inplace() -> None:
2712+
# GH 691
2713+
groupby = pd.DataFrame({"a": range(3), "b": range(3)}).groupby("a")
2714+
check(assert_type(groupby.fillna(0), pd.DataFrame), pd.DataFrame)
2715+
check(assert_type(groupby.fillna(0, inplace=False), pd.DataFrame), pd.DataFrame)
2716+
if TYPE_CHECKING_INVALID_USAGE:
2717+
groupby.fillna(0, inplace=True) # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]

0 commit comments

Comments
 (0)