Skip to content

Fixed metadata propagation in Dataframe.any #52922

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10958,9 +10958,14 @@ def any( # type: ignore[override]
) -> Series:
# error: Incompatible return value type (got "Union[Series, bool]",
# expected "Series")
return self._logical_func( # type: ignore[return-value]

result = self._logical_func(
"any", nanops.nanany, axis, bool_only, skipna, **kwargs
)
if isinstance(result, (np.bool_, bool)):
return result # type: ignore[return-value]
Copy link
Member

Choose a reason for hiding this comment

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

Could add bool | np.bool__ to the return types (but then you might need to add ignores elsewhere in pandas where any() is called)

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 for your suggestion, let me try

Copy link
Member

Choose a reason for hiding this comment

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

You probably need to add ignores here:

pandas/core/reshape/encoding.py:458: error: Item "bool" of "Union[Series, bool_, bool]" has no attribute "any" [union-attr]
pandas/core/reshape/encoding.py:461: error: Item "bool_" of "Union[Series, bool_, bool]" has no attribute "idxmax" [union-attr]
pandas/core/reshape/encoding.py:461: error: Item "bool" of "Union[Series, bool_, bool]" has no attribute "idxmax" [union-attr]


return result.__finalize__(self)

@doc(make_doc("all", ndim=2))
def all(
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 @@ -410,7 +410,6 @@
# Reductions
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("any")),
marks=not_implemented_mark,
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("sum")),
Expand Down