Skip to content

REF: de-nest Series.__setitem__ #32078

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 22 commits into from
Mar 7, 2020
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
02d37ec
re-order check
jbrockmendel Feb 11, 2020
2dc9376
CLN: de-nest bits of Series.__setitem__
jbrockmendel Feb 11, 2020
294a37d
linearize Series.__setitem__
jbrockmendel Feb 11, 2020
6e656ac
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 11, 2020
38c7a5e
revert
jbrockmendel Feb 11, 2020
5a209fa
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 12, 2020
dacfb42
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 12, 2020
db2468b
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 12, 2020
af21172
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 12, 2020
dc88626
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 18, 2020
af0a443
revert
jbrockmendel Feb 18, 2020
e4d68d4
CLN: simplify Series.__setitem__
jbrockmendel Feb 18, 2020
df935e2
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 21, 2020
cd13941
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 22, 2020
ec4a201
add assertion
jbrockmendel Feb 22, 2020
a19c349
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 23, 2020
f0cdc67
restore symmetry
jbrockmendel Feb 23, 2020
3e2cf68
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Feb 25, 2020
70f310d
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Mar 3, 2020
f8d5112
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Mar 3, 2020
3d8694f
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Mar 5, 2020
779e813
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel Mar 5, 2020
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
14 changes: 8 additions & 6 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,14 +978,15 @@ def __setitem__(self, key, value):
key = com.apply_if_callable(key, self)
cacher_needs_updating = self._check_is_chained_assignment_possible()

if key is Ellipsis:
key = slice(None)

try:
self._set_with_engine(key, value)
except (KeyError, ValueError):
values = self._values
if is_integer(key) and not self.index.inferred_type == "integer":
values[key] = value
elif key is Ellipsis:
self[:] = value
else:
self.loc[key] = value

Expand All @@ -1003,9 +1004,10 @@ def __setitem__(self, key, value):
self._where(~key, value, inplace=True)
return
except InvalidIndexError:
pass
self._set_values(key.astype(np.bool_), value)

self._set_with(key, value)
else:
self._set_with(key, value)

if cacher_needs_updating:
self._maybe_update_cacher()
Expand Down Expand Up @@ -1046,13 +1048,13 @@ def _set_with(self, key, value):
else:
key_type = lib.infer_dtype(key, skipna=False)

# Note: key_type == "boolean" should not occur because that
# should be caught by the is_bool_indexer check in __setitem__
if key_type == "integer":
if self.index.inferred_type == "integer":
self._set_labels(key, value)
else:
return self._set_values(key, value)
elif key_type == "boolean":
self._set_values(key.astype(np.bool_), value)
else:
self._set_labels(key, value)

Expand Down