diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 68308b2f83b60..801902a7aa4b7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -33,7 +33,6 @@ from pandas.util._decorators import Appender, Substitution, rewrite_axis_style_signature from pandas.util._validators import validate_bool_kwarg, validate_fillna_kwargs -from pandas.core.dtypes.cast import maybe_promote, maybe_upcast_putmask from pandas.core.dtypes.common import ( ensure_int64, ensure_object, @@ -968,15 +967,12 @@ def squeeze(self, axis=None): 1 """ axis = self._AXIS_NAMES if axis is None else (self._get_axis_number(axis),) - try: - return self.iloc[ - tuple( - 0 if i in axis and len(a) == 1 else slice(None) - for i, a in enumerate(self.axes) - ) - ] - except Exception: - return self + return self.iloc[ + tuple( + 0 if i in axis and len(a) == 1 else slice(None) + for i, a in enumerate(self.axes) + ) + ] def swaplevel(self, i=-2, j=-1, axis=0): """ @@ -9051,22 +9047,9 @@ def _where( # try to not change dtype at first (if try_quick) if try_quick: - try: - new_other = com.values_from_object(self) - new_other = new_other.copy() - new_other[icond] = other - other = new_other - except Exception: - try_quick = False - - # let's create a new (if we failed at the above - # or not try_quick - if not try_quick: - - dtype, fill_value = maybe_promote(other.dtype) - new_other = np.empty(len(icond), dtype=dtype) - new_other.fill(fill_value) - maybe_upcast_putmask(new_other, icond, other) + new_other = com.values_from_object(self) + new_other = new_other.copy() + new_other[icond] = other other = new_other else: diff --git a/pandas/core/series.py b/pandas/core/series.py index 922977bc04d63..321562d239e63 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1282,11 +1282,6 @@ def _set_with(self, key, value): if is_scalar(key): key = [key] - elif not isinstance(key, (list, Series, np.ndarray)): - try: - key = list(key) - except Exception: - key = [key] if isinstance(key, Index): key_type = key.inferred_type