Skip to content

CLN: Exception in generic, series #28434

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
Sep 17, 2019
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
35 changes: 9 additions & 26 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note below on 1291 we check for Index, which the check on 1285 doesnt do. The only time we actually get to 1287 in the tests is with a DatetimeIndex, which we should not be casting to list.

except Exception:
key = [key]

if isinstance(key, Index):
key_type = key.inferred_type
Expand Down