diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a28f89a79a880..490d3b8f4e003 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -701,10 +701,8 @@ def pop(self: FrameOrSeries, item) -> FrameOrSeries: """ result = self[item] del self[item] - try: + if self.ndim == 2: result._reset_cacher() - except AttributeError: - pass return result @@ -3255,14 +3253,9 @@ def _maybe_update_cacher( if ref is None: del self._cacher else: - # Note: we need to call ref._maybe_cache_changed even in the - # case where it will raise. (Uh, not clear why) - try: + if len(self) == len(ref): + # otherwise, either self or ref has swapped in new arrays ref._maybe_cache_changed(cacher[0], self) - except AssertionError: - # ref._mgr.setitem can raise - # AssertionError because of shape mismatch - pass if verify_is_copy: self._check_setitem_copy(stacklevel=5, t="referant") diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 71efde1cc5380..366ea54a510ef 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -51,7 +51,6 @@ from pandas.core.dtypes.dtypes import ExtensionDtype from pandas.core.dtypes.generic import ( ABCDataFrame, - ABCExtensionArray, ABCIndexClass, ABCPandasArray, ABCSeries, @@ -2765,9 +2764,10 @@ def _safe_reshape(arr, new_shape): """ if isinstance(arr, ABCSeries): arr = arr._values - if not isinstance(arr, ABCExtensionArray): - # TODO(EA2D): special case not needed with 2D EAs - arr = arr.reshape(new_shape) + if not is_extension_array_dtype(arr.dtype): + # Note: this will include TimedeltaArray and tz-naive DatetimeArray + # TODO(EA2D): special case will be unnecessary with 2D EAs + arr = np.asarray(arr).reshape(new_shape) return arr