Skip to content

Commit 0c55e91

Browse files
authored
CLN: avoid catching AssertionError, AttributeError in NDFrame methods (#33615)
1 parent 04f2c2b commit 0c55e91

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

pandas/core/generic.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,8 @@ def pop(self: FrameOrSeries, item) -> FrameOrSeries:
702702
"""
703703
result = self[item]
704704
del self[item]
705-
try:
705+
if self.ndim == 2:
706706
result._reset_cacher()
707-
except AttributeError:
708-
pass
709707

710708
return result
711709

@@ -3256,14 +3254,9 @@ def _maybe_update_cacher(
32563254
if ref is None:
32573255
del self._cacher
32583256
else:
3259-
# Note: we need to call ref._maybe_cache_changed even in the
3260-
# case where it will raise. (Uh, not clear why)
3261-
try:
3257+
if len(self) == len(ref):
3258+
# otherwise, either self or ref has swapped in new arrays
32623259
ref._maybe_cache_changed(cacher[0], self)
3263-
except AssertionError:
3264-
# ref._mgr.setitem can raise
3265-
# AssertionError because of shape mismatch
3266-
pass
32673260

32683261
if verify_is_copy:
32693262
self._check_setitem_copy(stacklevel=5, t="referant")

pandas/core/internals/blocks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from pandas.core.dtypes.dtypes import ExtensionDtype
5252
from pandas.core.dtypes.generic import (
5353
ABCDataFrame,
54-
ABCExtensionArray,
5554
ABCIndexClass,
5655
ABCPandasArray,
5756
ABCSeries,
@@ -2765,9 +2764,10 @@ def _safe_reshape(arr, new_shape):
27652764
"""
27662765
if isinstance(arr, ABCSeries):
27672766
arr = arr._values
2768-
if not isinstance(arr, ABCExtensionArray):
2769-
# TODO(EA2D): special case not needed with 2D EAs
2770-
arr = arr.reshape(new_shape)
2767+
if not is_extension_array_dtype(arr.dtype):
2768+
# Note: this will include TimedeltaArray and tz-naive DatetimeArray
2769+
# TODO(EA2D): special case will be unnecessary with 2D EAs
2770+
arr = np.asarray(arr).reshape(new_shape)
27712771
return arr
27722772

27732773

0 commit comments

Comments
 (0)