Skip to content

Commit 3d90ad4

Browse files
committed
BUG: Treat a list/ndarray identically for iloc indexing with list-like (GH5006)
1 parent 52021f4 commit 3d90ad4

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Diff for: doc/source/release.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ API Changes
297297
(:issue:`4501`)
298298
- Support non-unique axes in a Panel via indexing operations (:issue:`4960`)
299299

300-
301300
Internal Refactoring
302301
~~~~~~~~~~~~~~~~~~~~
303302

@@ -566,7 +565,7 @@ Bug Fixes
566565
- Provide automatic conversion of ``object`` dtypes on fillna, related (:issue:`5103`)
567566
- Fixed a bug where default options were being overwritten in the option
568567
parser cleaning (:issue:`5121`).
569-
568+
- Treat a list/ndarray identically for ``iloc`` indexing with list-like (:issue:`5006`)
570569

571570
pandas 0.12.0
572571
-------------

Diff for: pandas/core/indexing.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,9 @@ def _getitem_axis(self, key, axis=0):
10921092
else:
10931093

10941094
if _is_list_like(key):
1095-
pass
1095+
1096+
# force an actual list
1097+
key = list(key)
10961098
else:
10971099
key = self._convert_scalar_indexer(key, axis)
10981100

Diff for: pandas/tests/test_indexing.py

+7
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,15 @@ def test_iloc_getitem_list_int(self):
333333

334334
# list of ints
335335
self.check_result('list int', 'iloc', [0,1,2], 'ix', { 0 : [0,2,4], 1 : [0,3,6], 2: [0,4,8] }, typs = ['ints'])
336+
self.check_result('list int', 'iloc', [2], 'ix', { 0 : [4], 1 : [6], 2: [8] }, typs = ['ints'])
336337
self.check_result('list int', 'iloc', [0,1,2], 'indexer', [0,1,2], typs = ['labels','mixed','ts','floats','empty'], fails = IndexError)
337338

339+
# array of ints
340+
# (GH5006), make sure that a single indexer is returning the correct type
341+
self.check_result('array int', 'iloc', np.array([0,1,2]), 'ix', { 0 : [0,2,4], 1 : [0,3,6], 2: [0,4,8] }, typs = ['ints'])
342+
self.check_result('array int', 'iloc', np.array([2]), 'ix', { 0 : [4], 1 : [6], 2: [8] }, typs = ['ints'])
343+
self.check_result('array int', 'iloc', np.array([0,1,2]), 'indexer', [0,1,2], typs = ['labels','mixed','ts','floats','empty'], fails = IndexError)
344+
338345
def test_iloc_getitem_dups(self):
339346

340347
# no dups in panel (bug?)

0 commit comments

Comments
 (0)