Skip to content

CLN: avoid catching AssertionError, AttributeError in NDFrame methods #33615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
from pandas.core.dtypes.dtypes import ExtensionDtype
from pandas.core.dtypes.generic import (
ABCDataFrame,
ABCExtensionArray,
ABCIndexClass,
ABCPandasArray,
ABCSeries,
Expand Down Expand Up @@ -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


Expand Down