Skip to content

BUG: bug in setitem with multi-index and a 0-dim ndarray (GH7218) #7219

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 23, 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
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,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`)
- Bug in setitem with a single value, multi-index and integer indices (:issue:`7190`, :issue:`7218`)
- Bug in expressions evaluation with reversed ops, showing in series-dataframe ops (:issue:`7198`, :issue:`7192`)
- Bug in multi-axis indexing with > 2 ndim and a multi-index (:issue:`7199`)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _setitem_with_indexer(self, indexer, value):

# require that we are setting the right number of values that
# we are indexing
if is_list_like(value) and lplane_indexer != len(value):
if is_list_like(value) and np.iterable(value) and lplane_indexer != len(value):

if len(obj[idx]) != len(value):
raise ValueError(
Expand Down Expand Up @@ -386,7 +386,7 @@ def setter(item, v):

def can_do_equal_len():
""" return True if we have an equal len settable """
if not len(labels) == 1:
if not len(labels) == 1 or not np.iterable(value):
return False

l = len(value)
Expand Down
14 changes: 10 additions & 4 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,20 @@ def test_loc_setitem_multiindex(self):
self.assertEqual(result, 0)

df = DataFrame(-999,columns=['A', 'w', 'l', 'a', 'x', 'X', 'd', 'profit'], index=index)
df.loc[(t,n),'X'] = 0
df.loc[(t,n),'X'] = 1
result = df.loc[(t,n),'X']
self.assertEqual(result, 0)
self.assertEqual(result, 1)

df = DataFrame(columns=['A', 'w', 'l', 'a', 'x', 'X', 'd', 'profit'], index=index)
df.loc[(t,n),'X'] = 0
df.loc[(t,n),'X'] = 2
result = df.loc[(t,n),'X']
self.assertEqual(result, 0)
self.assertEqual(result, 2)

# GH 7218, assinging with 0-dim arrays
df = DataFrame(-999,columns=['A', 'w', 'l', 'a', 'x', 'X', 'd', 'profit'], index=index)
df.loc[(t,n), 'X'] = np.array(3)
result = df.loc[(t,n),'X']
self.assertEqual(result,3)

def test_loc_setitem_dups(self):

Expand Down