Skip to content

Fix slicer assignment bug #28131

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 5 commits into from
Aug 28, 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Interval
Indexing
^^^^^^^^

-
- Bug in assignment using a reverse slicer (:issue:`26939`)
-

Missing
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def length_of_indexer(indexer, target=None) -> int:
if step is None:
step = 1
elif step < 0:
start, stop = stop + 1, start + 1
step = -step
return (stop - start + step - 1) // step
elif isinstance(indexer, (ABCSeries, ABCIndexClass, np.ndarray, list)):
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,16 @@ def test_series_indexing_zerodim_np_array(self):
result = s.loc[np.array(0)]
assert result == 1

def test_loc_reverse_assignment(self):
# GH26939
data = [1, 2, 3, 4, 5, 6] + [None] * 4
expected = Series(data, index=range(2010, 2020))

result = pd.Series(index=range(2010, 2020))
result.loc[2015:2010:-1] = [6, 5, 4, 3, 2, 1]

tm.assert_series_equal(result, expected)


def test_series_loc_getitem_label_list_missing_values():
# gh-11428
Expand Down