Skip to content

CLN: Remove special cases in indexing ops #52063

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 1 commit into from
Mar 18, 2023
Merged
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
22 changes: 5 additions & 17 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,8 @@ def _maybe_mask_setitem_value(self, indexer, value):

if is_scalar_indexer(icols, self.ndim - 1) and ndim == 1:
# e.g. test_loc_setitem_boolean_mask_allfalse
if len(newkey) == 0:
# FIXME: kludge for test_loc_setitem_boolean_mask_allfalse
# TODO(GH#45333): may be fixed when deprecation is enforced

value = value.iloc[:0]
else:
# test_loc_setitem_ndframe_values_alignment
value = self.obj.iloc._align_series(indexer, value)
# test_loc_setitem_ndframe_values_alignment
value = self.obj.iloc._align_series(indexer, value)
indexer = (newkey, icols)

elif (
Expand All @@ -757,14 +751,8 @@ def _maybe_mask_setitem_value(self, indexer, value):
indexer = (newkey, icols)

elif ndim == 2 and value.shape[1] == 1:
if len(newkey) == 0:
# FIXME: kludge for
# test_loc_setitem_all_false_boolean_two_blocks
# TODO(GH#45333): may be fixed when deprecation is enforced
value = value.iloc[:0]
else:
# test_loc_setitem_ndframe_values_alignment
value = self.obj.iloc._align_frame(indexer, value)
# test_loc_setitem_ndframe_values_alignment
value = self.obj.iloc._align_frame(indexer, value)
indexer = (newkey, icols)
elif com.is_bool_indexer(indexer):
indexer = indexer.nonzero()[0]
Expand Down Expand Up @@ -2255,7 +2243,7 @@ def ravel(i):
new_ix = Index([new_ix])
else:
new_ix = Index(new_ix)
if ser.index.equals(new_ix) or not len(new_ix):
if ser.index.equals(new_ix):
return ser._values.copy()

return ser.reindex(new_ix)._values
Expand Down