Skip to content

BUG: duplicate indexing with setitem with iloc (GH6766) #7006

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 30, 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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ Bug Fixes
- Bug in enabling ``subplots=True`` in ``DataFrame.plot`` only has single column raises ``TypeError``, and ``Series.plot`` raises ``AttributeError`` (:issue:`6951`)
- Bug in ``DataFrame.plot`` draws unnecessary axes when enabling ``subplots`` and ``kind=scatter`` (:issue:`6951`)
- Bug in ``read_csv`` from a filesystem with non-utf-8 encoding (:issue:`6807`)
- Bug in ``iloc`` when setting / aligning (:issue:``6766`)

pandas 0.13.1
-------------
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def setter(item, v):
s._data = s._data.setitem(indexer=pi, value=v)
s._maybe_update_cacher(clear=True)

# reset the sliced object if unique
self.obj[item] = s

def can_do_equal_len():
Expand Down
30 changes: 30 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,36 @@ def test_loc_setitem_dups(self):
df.loc[indexer]*=2.0
assert_frame_equal(df.loc[indexer],2.0*df_orig.loc[indexer])

def test_iloc_setitem_dups(self):

# GH 6766
# iloc with a mask aligning from another iloc
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)

expected = df.fillna(3)
expected['A'] = expected['A'].astype('float64')
inds = np.isnan(df.iloc[:, 0])
mask = inds[inds].index
df.iloc[mask,0] = df.iloc[mask,2]
assert_frame_equal(df, expected)

# del a dup column across blocks
expected = DataFrame({ 0 : [1,2], 1 : [3,4] })
expected.columns=['B','B']
del df['A']
assert_frame_equal(df, expected)

# assign back to self
df.iloc[[0,1],[0,1]] = df.iloc[[0,1],[0,1]]
assert_frame_equal(df, expected)

# reversed x 2
df.iloc[[1,0],[0,1]] = df.iloc[[1,0],[0,1]].reset_index(drop=True)
df.iloc[[1,0],[0,1]] = df.iloc[[1,0],[0,1]].reset_index(drop=True)
assert_frame_equal(df, expected)

def test_chained_getitem_with_lists(self):

# GH6394
Expand Down