Skip to content

Commit

Permalink
GH987 Add limit_area parameter in ffill and bfill methods (pandas…
Browse files Browse the repository at this point in the history
…-dev#1028)

* add limit_area parameter in ffill and bfill methods

* add limit_area parameter to Series bfill and ffill methods

* add limit_area parameter to Series bfill and ffill methods

* remove irrelevant definition of series bfill
  • Loading branch information
hyperc54 authored Nov 11, 2024
1 parent 8d9be32 commit 25b7a9e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ class DataFrame(NDFrame, OpsMixin):
axis: Axis | None = ...,
inplace: Literal[True],
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> None: ...
@overload
Expand All @@ -1665,6 +1666,7 @@ class DataFrame(NDFrame, OpsMixin):
axis: Axis | None = ...,
inplace: Literal[False] = ...,
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> DataFrame: ...
def clip(
Expand Down Expand Up @@ -1736,6 +1738,7 @@ class DataFrame(NDFrame, OpsMixin):
axis: Axis | None = ...,
inplace: Literal[True],
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> None: ...
@overload
Expand All @@ -1745,6 +1748,7 @@ class DataFrame(NDFrame, OpsMixin):
axis: Axis | None = ...,
inplace: Literal[False] = ...,
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> DataFrame: ...
def filter(
Expand Down
14 changes: 4 additions & 10 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex | None = ...,
inplace: Literal[True],
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> None: ...
@overload
Expand All @@ -1309,6 +1310,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex | None = ...,
inplace: Literal[False] = ...,
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> Series[S1]: ...
@overload
Expand All @@ -1318,6 +1320,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex | None = ...,
inplace: Literal[True],
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> None: ...
@overload
Expand All @@ -1327,18 +1330,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
axis: AxisIndex | None = ...,
inplace: Literal[False] = ...,
limit: int | None = ...,
limit_area: Literal["inside", "outside"] | None = ...,
downcast: dict | None = ...,
) -> Series[S1]: ...
@overload
def bfill(
self,
*,
value: S1 | dict | Series[S1] | DataFrame,
axis: AxisIndex = ...,
inplace: _bool = ...,
limit: int | None = ...,
downcast: dict | None = ...,
) -> Series[S1] | None: ...
def interpolate(
self,
method: InterpolateOptions = ...,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2328,15 +2328,25 @@ def test_types_ffill() -> None:
df = pd.DataFrame([[1, 2, 3]])
check(assert_type(df.ffill(), pd.DataFrame), pd.DataFrame)
check(assert_type(df.ffill(inplace=False), pd.DataFrame), pd.DataFrame)
check(
assert_type(df.ffill(inplace=False, limit_area="inside"), pd.DataFrame),
pd.DataFrame,
)
assert assert_type(df.ffill(inplace=True), None) is None
assert assert_type(df.ffill(inplace=True, limit_area="outside"), None) is None


def test_types_bfill() -> None:
# GH 44
df = pd.DataFrame([[1, 2, 3]])
check(assert_type(df.bfill(), pd.DataFrame), pd.DataFrame)
check(assert_type(df.bfill(inplace=False), pd.DataFrame), pd.DataFrame)
check(
assert_type(df.bfill(inplace=False, limit_area="inside"), pd.DataFrame),
pd.DataFrame,
)
assert assert_type(df.bfill(inplace=True), None) is None
assert assert_type(df.bfill(inplace=True, limit_area="outside"), None) is None


def test_types_replace() -> None:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,13 @@ def test_types_bfill() -> None:
s1 = pd.Series([1, 2, 3])
check(assert_type(s1.bfill(), "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s1.bfill(inplace=False), "pd.Series[int]"), pd.Series, np.integer)
check(
assert_type(s1.bfill(inplace=False, limit_area="inside"), "pd.Series[int]"),
pd.Series,
np.integer,
)
assert assert_type(s1.bfill(inplace=True), None) is None
assert assert_type(s1.bfill(inplace=True, limit_area="outside"), None) is None


def test_types_ewm() -> None:
Expand Down Expand Up @@ -1205,7 +1211,13 @@ def test_types_ffill() -> None:
s1 = pd.Series([1, 2, 3])
check(assert_type(s1.ffill(), "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s1.ffill(inplace=False), "pd.Series[int]"), pd.Series, np.integer)
check(
assert_type(s1.ffill(inplace=False, limit_area="inside"), "pd.Series[int]"),
pd.Series,
np.integer,
)
assert assert_type(s1.ffill(inplace=True), None) is None
assert assert_type(s1.ffill(inplace=True, limit_area="outside"), None) is None


def test_types_as_type() -> None:
Expand Down

0 comments on commit 25b7a9e

Please sign in to comment.