Skip to content

Commit 8a41508

Browse files
authored
fix(frame): add arguments for stack method (#926)
* fix(frame): add arguments for stack method * feat: test future_stack only for LTE 2.2 * fix: include both test in PD_LTE_22 condition --------- Co-authored-by: Quentin FLEURENT NAMBOT <[email protected]>
1 parent a66ea6b commit 8a41508

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pandas-stubs/core/frame.pyi

+6-1
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,13 @@ class DataFrame(NDFrame, OpsMixin):
11911191
margins_name: _str = ...,
11921192
observed: _bool = ...,
11931193
) -> DataFrame: ...
1194+
@overload
1195+
def stack(
1196+
self, level: Level | list[Level] = ..., dropna: _bool = ..., sort: _bool = ...
1197+
) -> DataFrame | Series[Any]: ...
1198+
@overload
11941199
def stack(
1195-
self, level: Level | list[Level] = ..., dropna: _bool = ...
1200+
self, level: Level | list[Level] = ..., future_stack: _bool = ...
11961201
) -> DataFrame | Series[Any]: ...
11971202
def explode(
11981203
self, column: Sequence[Hashable], ignore_index: _bool = ...

tests/test_frame.py

+15
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,21 @@ def test_frame_stack() -> None:
22562256
),
22572257
pd.Series,
22582258
)
2259+
if PD_LTE_22:
2260+
check(
2261+
assert_type(
2262+
df_multi_level_cols2.stack(0, future_stack=False),
2263+
Union[pd.DataFrame, "pd.Series[Any]"],
2264+
),
2265+
pd.DataFrame,
2266+
)
2267+
check(
2268+
assert_type(
2269+
df_multi_level_cols2.stack(0, dropna=True, sort=True),
2270+
Union[pd.DataFrame, "pd.Series[Any]"],
2271+
),
2272+
pd.DataFrame,
2273+
)
22592274

22602275

22612276
def test_frame_reindex() -> None:

0 commit comments

Comments
 (0)