Skip to content

Commit a7e535b

Browse files
cpcloudjreback
authored andcommitted
BUG: ix should return a Series for duplicate indices (GH7150)
1 parent 5dd8f2c commit a7e535b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

doc/source/v0.14.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Bug Fixes
164164

165165

166166

167-
167+
- Bug in ``.ix`` getitem should always return a Series (:issue:`7150`)
168168

169169

170170

pandas/core/indexing.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def __getitem__(self, arg):
3535
class IndexingError(Exception):
3636
pass
3737

38-
3938
class _NDFrameIndexer(object):
4039
_valid_types = None
4140
_exception = KeyError
@@ -61,7 +60,9 @@ def __iter__(self):
6160
def __getitem__(self, key):
6261
if type(key) is tuple:
6362
try:
64-
return self.obj.get_value(*key)
63+
values = self.obj.get_value(*key)
64+
if np.isscalar(values):
65+
return values
6566
except Exception:
6667
pass
6768

@@ -1101,8 +1102,6 @@ class _IXIndexer(_NDFrameIndexer):
11011102
""" A primarily location based indexer, with integer fallback """
11021103

11031104
def _has_valid_type(self, key, axis):
1104-
ax = self.obj._get_axis(axis)
1105-
11061105
if isinstance(key, slice):
11071106
return True
11081107

pandas/tests/test_indexing.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -3570,8 +3570,14 @@ def test_float_index_to_mixed(self):
35703570
'a': [10] * 10}),
35713571
df)
35723572

3573+
def test_duplicate_ix_returns_series(self):
3574+
df = DataFrame(np.random.randn(3, 3), index=[0.1, 0.2, 0.2],
3575+
columns=list('abc'))
3576+
r = df.ix[0.2, 'a']
3577+
e = df.loc[0.2, 'a']
3578+
tm.assert_series_equal(r, e)
3579+
35733580

35743581
if __name__ == '__main__':
3575-
import nose
35763582
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
35773583
exit=False)

0 commit comments

Comments
 (0)