Skip to content

BUG: Bug in repeated indexing of object with resultant non-unique index (GH5678) #5680

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 1 commit into from
Dec 11, 2013
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ Bug Fixes
- Bug in selecting from a non-unique index with ``loc`` (:issue:`5553`)
- Bug in groupby returning non-consistent types when user function returns a ``None``, (:issue:`5592`)
- Work around regression in numpy 1.7.0 which erroneously raises IndexError from ``ndarray.item`` (:issue:`5666`)
- Bug in repeated indexing of object with resultant non-unique index (:issue:`5678`)

pandas 0.12.0
-------------
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,10 @@ def _slice(self, slobj, axis=0, raise_on_error=False, typ=None):

def __getitem__(self, key):
try:
return self.index.get_value(self, key)
result = self.index.get_value(self, key)
if isinstance(result, np.ndarray):
return self._constructor(result,index=[key]*len(result)).__finalize__(self)
return result
except InvalidIndexError:
pass
except (KeyError, ValueError):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ def test_at_timestamp(self):
def test_iat_invalid_args(self):
pass

def test_repeated_getitem_dups(self):
# GH 5678
# repeated gettitems on a dup index returing a ndarray
df = DataFrame(np.random.random_sample((20,5)), index=['ABCDE'[x%5] for x in range(20)])
expected = df.loc['A',0]
result = df.loc[:,0].loc['A']
assert_series_equal(result,expected)

def test_iloc_getitem_int(self):

# integer
Expand Down