Skip to content

Commit fe50456

Browse files
jbrockmendelproost
authored andcommitted
CLN: Exception in generic, series (pandas-dev#28434)
1 parent 20b307d commit fe50456

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

pandas/core/generic.py

+9-26
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from pandas.util._decorators import Appender, Substitution, rewrite_axis_style_signature
3434
from pandas.util._validators import validate_bool_kwarg, validate_fillna_kwargs
3535

36-
from pandas.core.dtypes.cast import maybe_promote, maybe_upcast_putmask
3736
from pandas.core.dtypes.common import (
3837
ensure_int64,
3938
ensure_object,
@@ -968,15 +967,12 @@ def squeeze(self, axis=None):
968967
1
969968
"""
970969
axis = self._AXIS_NAMES if axis is None else (self._get_axis_number(axis),)
971-
try:
972-
return self.iloc[
973-
tuple(
974-
0 if i in axis and len(a) == 1 else slice(None)
975-
for i, a in enumerate(self.axes)
976-
)
977-
]
978-
except Exception:
979-
return self
970+
return self.iloc[
971+
tuple(
972+
0 if i in axis and len(a) == 1 else slice(None)
973+
for i, a in enumerate(self.axes)
974+
)
975+
]
980976

981977
def swaplevel(self, i=-2, j=-1, axis=0):
982978
"""
@@ -9053,22 +9049,9 @@ def _where(
90539049
# try to not change dtype at first (if try_quick)
90549050
if try_quick:
90559051

9056-
try:
9057-
new_other = com.values_from_object(self)
9058-
new_other = new_other.copy()
9059-
new_other[icond] = other
9060-
other = new_other
9061-
except Exception:
9062-
try_quick = False
9063-
9064-
# let's create a new (if we failed at the above
9065-
# or not try_quick
9066-
if not try_quick:
9067-
9068-
dtype, fill_value = maybe_promote(other.dtype)
9069-
new_other = np.empty(len(icond), dtype=dtype)
9070-
new_other.fill(fill_value)
9071-
maybe_upcast_putmask(new_other, icond, other)
9052+
new_other = com.values_from_object(self)
9053+
new_other = new_other.copy()
9054+
new_other[icond] = other
90729055
other = new_other
90739056

90749057
else:

pandas/core/series.py

-5
Original file line numberDiff line numberDiff line change
@@ -1282,11 +1282,6 @@ def _set_with(self, key, value):
12821282

12831283
if is_scalar(key):
12841284
key = [key]
1285-
elif not isinstance(key, (list, Series, np.ndarray)):
1286-
try:
1287-
key = list(key)
1288-
except Exception:
1289-
key = [key]
12901285

12911286
if isinstance(key, Index):
12921287
key_type = key.inferred_type

0 commit comments

Comments
 (0)