Skip to content

Commit

Permalink
BUG: support pandas objects in iloc with old numpy versions
Browse files Browse the repository at this point in the history
closes #17193
  • Loading branch information
toobaz committed Aug 7, 2017
1 parent 929c66f commit 8b35f26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ Indexing
- Fixes bug where indexing with ``np.inf`` caused an ``OverflowError`` to be raised (:issue:`16957`)
- Bug in reindexing on an empty ``CategoricalIndex`` (:issue:`16770`)
- Fixes ``DataFrame.loc`` for setting with alignment and tz-aware ``DatetimeIndex`` (:issue:`16889`)
- Fixes ``.iloc`` with numpy 1.7 or 1.8 when passed a pandas object (:issue:`17193`)

I/O
^^^
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ def _is_empty_indexer(indexer):

# set
else:
# Work around GH 6168 to support numpy 1.7 and 1.8
indexer = getattr(indexer, 'values', indexer)
values[indexer] = value

# coerce and try to infer the dtypes of the result
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ def test_iloc_setitem_list(self):
index=["A", "B", "C"], columns=["A", "B", "C"])
tm.assert_frame_equal(df, expected)

def test_iloc_setitem_pandas_object(self):
# GH 17193
s_orig = Series(range(4))
expected = Series([0, -1, -2, 3])

s = s_orig.copy()
s.iloc[Series([1, 2])] = [-1, -2]
tm.assert_series_equal(s, expected)

s = s_orig.copy()
s.iloc[pd.Index([1, 2])] = [-1, -2]
tm.assert_series_equal(s, expected)

def test_iloc_setitem_dups(self):

# GH 6766
Expand Down

0 comments on commit 8b35f26

Please sign in to comment.