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
  • Loading branch information
toobaz committed Aug 8, 2017
1 parent 929c66f commit b0a4b6b
Show file tree
Hide file tree
Showing 3 changed files with 17 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`)
- Avoids ``IndexError`` when passing an Index or Series to ``.iloc`` with older numpy (:issue:`17193`)

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

# set
else:
if _np_version_under1p9:
# Work around GH 6168 to support old numpy
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, affecting old numpy (1.7 and 1.8)
s_orig = Series([0, 1, 2, 3])
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 b0a4b6b

Please sign in to comment.