Skip to content

Commit 0999fe3

Browse files
jbrockmendelproost
authored andcommitted
CLN: avoid catching Exception in generic (pandas-dev#28370)
1 parent 37a5fa5 commit 0999fe3

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

pandas/core/generic.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
is_datetime64tz_dtype,
4545
is_dict_like,
4646
is_extension_array_dtype,
47+
is_float,
4748
is_integer,
4849
is_list_like,
4950
is_number,
@@ -1525,16 +1526,12 @@ def __pos__(self):
15251526
return self.__array_wrap__(arr)
15261527

15271528
def __invert__(self):
1528-
try:
1529-
arr = operator.inv(com.values_from_object(self))
1530-
return self.__array_wrap__(arr)
1531-
except Exception:
1532-
1529+
if not self.size:
15331530
# inv fails with 0 len
1534-
if not np.prod(self.shape):
1535-
return self
1531+
return self
15361532

1537-
raise
1533+
arr = operator.inv(com.values_from_object(self))
1534+
return self.__array_wrap__(arr)
15381535

15391536
def __nonzero__(self):
15401537
raise ValueError(
@@ -5316,11 +5313,8 @@ def _check_inplace_setting(self, value):
53165313
if not self._is_numeric_mixed_type:
53175314

53185315
# allow an actual np.nan thru
5319-
try:
5320-
if np.isnan(value):
5321-
return True
5322-
except Exception:
5323-
pass
5316+
if is_float(value) and np.isnan(value):
5317+
return True
53245318

53255319
raise TypeError(
53265320
"Cannot do inplace boolean setting on "

0 commit comments

Comments
 (0)