Skip to content

Commit ed5726e

Browse files
committed
Merge pull request #5680 from jreback/dup_series
BUG: Bug in repeated indexing of object with resultant non-unique index (GH5678)
2 parents 90990db + 844a4ff commit ed5726e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ Bug Fixes
821821
- Bug in selecting from a non-unique index with ``loc`` (:issue:`5553`)
822822
- Bug in groupby returning non-consistent types when user function returns a ``None``, (:issue:`5592`)
823823
- Work around regression in numpy 1.7.0 which erroneously raises IndexError from ``ndarray.item`` (:issue:`5666`)
824+
- Bug in repeated indexing of object with resultant non-unique index (:issue:`5678`)
824825

825826
pandas 0.12.0
826827
-------------

pandas/core/series.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,10 @@ def _slice(self, slobj, axis=0, raise_on_error=False, typ=None):
481481

482482
def __getitem__(self, key):
483483
try:
484-
return self.index.get_value(self, key)
484+
result = self.index.get_value(self, key)
485+
if isinstance(result, np.ndarray):
486+
return self._constructor(result,index=[key]*len(result)).__finalize__(self)
487+
return result
485488
except InvalidIndexError:
486489
pass
487490
except (KeyError, ValueError):

pandas/tests/test_indexing.py

+8
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ def test_at_timestamp(self):
316316
def test_iat_invalid_args(self):
317317
pass
318318

319+
def test_repeated_getitem_dups(self):
320+
# GH 5678
321+
# repeated gettitems on a dup index returing a ndarray
322+
df = DataFrame(np.random.random_sample((20,5)), index=['ABCDE'[x%5] for x in range(20)])
323+
expected = df.loc['A',0]
324+
result = df.loc[:,0].loc['A']
325+
assert_series_equal(result,expected)
326+
319327
def test_iloc_getitem_int(self):
320328

321329
# integer

0 commit comments

Comments
 (0)