Skip to content
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

fix(frame): add arguments for stack method #926

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,13 @@ class DataFrame(NDFrame, OpsMixin):
margins_name: _str = ...,
observed: _bool = ...,
) -> DataFrame: ...
@overload
def stack(
self, level: Level | list[Level] = ..., dropna: _bool = ..., sort: _bool = ...
) -> DataFrame | Series[Any]: ...
@overload
def stack(
self, level: Level | list[Level] = ..., dropna: _bool = ...
self, level: Level | list[Level] = ..., future_stack: _bool = ...
) -> DataFrame | Series[Any]: ...
def explode(
self, column: Sequence[Hashable], ignore_index: _bool = ...
Expand Down
14 changes: 14 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,20 @@ def test_frame_stack() -> None:
),
pd.Series,
)
check(
assert_type(
df_multi_level_cols2.stack(0, future_stack=False),
Union[pd.DataFrame, "pd.Series[Any]"],
),
pd.DataFrame,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you surround this with if PD_LTE_22: as the future_stack parameter is being removed in the future, and it will allow the nightly tests that get run upon a merge to succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I just added the condition 👍

check(
assert_type(
df_multi_level_cols2.stack(0, dropna=True, sort=True),
Union[pd.DataFrame, "pd.Series[Any]"],
),
pd.DataFrame,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have to include the if PD_LTE_22 on this test as well, as the dropna argument will also change behavior in 3.0, so have one if statement surround both of the new tests you added.

To see this, do poe pytest --nightly on your current branch, and when you make the fix the problem will go away.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok nice I didn't notice the --nightly option to test with pandas 3! It seems to pass now



def test_frame_reindex() -> None:
Expand Down
Loading