Skip to content

BUG: Bug in setitem with a single item, and a multi-index and integer indices (GH7190) #7191

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
May 21, 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 @@ -533,6 +533,7 @@ Bug Fixes
- Bug in ``query``/``eval`` where global constants were not looked up correctly
(:issue:`7178`)
- Bug in recognizing out-of-bounds positional list indexers with ``iloc`` and a multi-axis tuple indexer (:issue:`7189`)
- Bug in setitem with a single value, multi-index and integer indices (:issue:`7190`)

pandas 0.13.1
-------------
Expand Down
6 changes: 1 addition & 5 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,7 @@ def _setitem_with_indexer(self, indexer, value):
obj = self.obj[item]
index = obj.index
idx = indexer[:info_axis][0]
try:
if idx in index:
idx = index.get_loc(idx)
except:
pass

plane_indexer = tuple([idx]) + indexer[info_axis + 1:]
lplane_indexer = _length_of_indexer(plane_indexer[0], index)

Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,17 @@ def test_loc_setitem(self):
expected = DataFrame({'a' : [0.5,-0.5,-1.5], 'b' : [0,1,2] })
assert_frame_equal(df,expected)

def test_loc_setitem_multiindex(self):

# GH7190
index = pd.MultiIndex.from_product([np.arange(0,100), np.arange(0, 80)], names=['time', 'firm'])
df = DataFrame(np.nan,columns=['A', 'w', 'l', 'a', 'x', 'X', 'd', 'profit'], index=index)
t, n = 0, 2

df.loc[(t,n),'X'] = 0
result = df.loc[(t,n),'X']
self.assertEqual(result, 0)

def test_loc_setitem_dups(self):

# GH 6541
Expand Down