From a7e535b3b5682f95d63b44cdf4bb75c18c1da015 Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Sat, 7 Jun 2014 17:29:17 -0400 Subject: [PATCH] BUG: ix should return a Series for duplicate indices (GH7150) --- doc/source/v0.14.1.txt | 2 +- pandas/core/indexing.py | 7 +++---- pandas/tests/test_indexing.py | 8 +++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 1cb6aadf3f40f..586e47ff4f303 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -164,7 +164,7 @@ Bug Fixes - +- Bug in ``.ix`` getitem should always return a Series (:issue:`7150`) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 68e5810751d08..45262575dcb37 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -35,7 +35,6 @@ def __getitem__(self, arg): class IndexingError(Exception): pass - class _NDFrameIndexer(object): _valid_types = None _exception = KeyError @@ -61,7 +60,9 @@ def __iter__(self): def __getitem__(self, key): if type(key) is tuple: try: - return self.obj.get_value(*key) + values = self.obj.get_value(*key) + if np.isscalar(values): + return values except Exception: pass @@ -1101,8 +1102,6 @@ class _IXIndexer(_NDFrameIndexer): """ A primarily location based indexer, with integer fallback """ def _has_valid_type(self, key, axis): - ax = self.obj._get_axis(axis) - if isinstance(key, slice): return True diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 96c67f2ff795c..7610ccc6cdf73 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -3570,8 +3570,14 @@ def test_float_index_to_mixed(self): 'a': [10] * 10}), df) + def test_duplicate_ix_returns_series(self): + df = DataFrame(np.random.randn(3, 3), index=[0.1, 0.2, 0.2], + columns=list('abc')) + r = df.ix[0.2, 'a'] + e = df.loc[0.2, 'a'] + tm.assert_series_equal(r, e) + if __name__ == '__main__': - import nose nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False)