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 the metadata propagation in Dataframe.std #52924

Merged
merged 4 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11069,7 +11069,11 @@ def std(
numeric_only: bool = False,
**kwargs,
):
return super().std(axis, skipna, ddof, numeric_only, **kwargs)
result = super().std(axis, skipna, ddof, numeric_only, **kwargs)
if isinstance(result, Series):
return result.__finalize__(self, method="std")
else:
return result
Copy link
Member

Choose a reason for hiding this comment

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

this should be unreachable, and looks like a case where we humans looking at the code can infer things which the type checker can't

I'd suggest

result = cast(Series, super().std(...)
return result.__finalize_(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much, Mr Gorelli! I appreciate your help so much, I will submit this:)


@doc(make_doc("skew", ndim=2))
def skew(
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("std")),
marks=not_implemented_mark,
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("mean")),
Expand Down