Skip to content

Commit 8f737b3

Browse files
authored
CLN: Remove __nonzero__ in favor of __bool__ (#59275)
1 parent a9b99f7 commit 8f737b3

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

pandas/core/generic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,14 +1491,12 @@ def __invert__(self) -> Self:
14911491
return res.__finalize__(self, method="__invert__")
14921492

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

1500-
__bool__ = __nonzero__
1501-
15021500
@final
15031501
def abs(self) -> Self:
15041502
"""

pandas/core/indexes/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,14 +2910,12 @@ def __iadd__(self, other):
29102910
return self + other
29112911

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

2919-
__bool__ = __nonzero__
2920-
29212919
# --------------------------------------------------------------------
29222920
# Set Operation Methods
29232921

pandas/core/internals/managers.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,9 @@ def make_empty(self, axes=None) -> Self:
263263
blocks = []
264264
return type(self).from_blocks(blocks, axes)
265265

266-
def __nonzero__(self) -> bool:
266+
def __bool__(self) -> bool:
267267
return True
268268

269-
# Python3 compat
270-
__bool__ = __nonzero__
271-
272269
def set_axis(self, axis: AxisInt, new_labels: Index) -> None:
273270
# Caller is responsible for ensuring we have an Index object.
274271
self._validate_set_axis(axis, new_labels)

0 commit comments

Comments
 (0)