Skip to content

CLN: Remove __nonzero__ in favor of __bool__ #59275

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

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,14 +1491,12 @@ def __invert__(self) -> Self:
return res.__finalize__(self, method="__invert__")

@final
def __nonzero__(self) -> NoReturn:
def __bool__(self) -> NoReturn:
raise ValueError(
f"The truth value of a {type(self).__name__} is ambiguous. "
"Use a.empty, a.bool(), a.item(), a.any() or a.all()."
)

__bool__ = __nonzero__

@final
def abs(self) -> Self:
"""
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2907,14 +2907,12 @@ def __iadd__(self, other):
return self + other

@final
def __nonzero__(self) -> NoReturn:
def __bool__(self) -> NoReturn:
raise ValueError(
f"The truth value of a {type(self).__name__} is ambiguous. "
"Use a.empty, a.bool(), a.item(), a.any() or a.all()."
)

__bool__ = __nonzero__

# --------------------------------------------------------------------
# Set Operation Methods

Expand Down
5 changes: 1 addition & 4 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,9 @@ def make_empty(self, axes=None) -> Self:
blocks = []
return type(self).from_blocks(blocks, axes)

def __nonzero__(self) -> bool:
def __bool__(self) -> bool:
return True

# Python3 compat
__bool__ = __nonzero__

def set_axis(self, axis: AxisInt, new_labels: Index) -> None:
# Caller is responsible for ensuring we have an Index object.
self._validate_set_axis(axis, new_labels)
Expand Down