Skip to content

BUG: duplicate (getitem) indexing with iloc (GH6766) #6799

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
Apr 4, 2014
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
8 changes: 6 additions & 2 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ def setitem(self, indexer, value):
values = self._try_coerce_result(values)
values = self._try_cast_result(values, dtype)
return [make_block(transf(values), self.items, self.ref_items,
ndim=self.ndim, fastpath=True)]
ndim=self.ndim, placement=self._ref_locs,
fastpath=True)]
except (ValueError, TypeError) as detail:
raise
except Exception as detail:
Expand Down Expand Up @@ -2902,7 +2903,10 @@ def fast_xs(self, loc, copy=False):

# non-unique (GH4726)
if not items.is_unique:
return self._interleave(items).ravel(), True
result = self._interleave(items)
if self.ndim == 2:
result = result.T
return result[loc], True

# unique
dtype = _interleaved_dtype(self.blocks)
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,19 @@ def test_iloc_getitem_dups(self):
# no dups in panel (bug?)
self.check_result('list int (dups)', 'iloc', [0,1,1,3], 'ix', { 0 : [0,2,2,6], 1 : [0,3,3,9] }, objs = ['series','frame'], typs = ['ints'])

# GH 6766
df1 = DataFrame([{'A':None, 'B':1},{'A':2, 'B':2}])
df2 = DataFrame([{'A':3, 'B':3},{'A':4, 'B':4}])
df = concat([df1, df2], axis=1)

# cross-sectional indexing
result = df.iloc[0,0]
self.assertTrue(isnull(result))

result = df.iloc[0,:]
expected = Series([np.nan,1,3,3],index=['A','B','A','B'])
assert_series_equal(result,expected)

def test_iloc_getitem_array(self):

# array like
Expand Down