Skip to content

Commit

Permalink
Fix rhs dict assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Apr 13, 2015
1 parent 85bab01 commit d69fa3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def _has_valid_positional_setitem_indexer(self, indexer):
return True

def _setitem_with_indexer(self, indexer, value):

self._has_valid_setitem_indexer(indexer)

# also has the side effect of consolidating in-place
Expand Down Expand Up @@ -486,8 +485,8 @@ def can_do_equal_len():
self.obj[item_labels[indexer[info_axis]]] = value
return

if isinstance(value, ABCSeries):
value = self._align_series(indexer, value)
if isinstance(value, (ABCSeries, dict)):
value = self._align_series(indexer, Series(value))

elif isinstance(value, ABCDataFrame):
value = self._align_frame(indexer, value)
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4411,6 +4411,16 @@ def test_slice_with_zero_step_raises(self):
self.assertRaisesRegexp(ValueError, 'slice step cannot be zero',
lambda: s.ix[::0])

def test_indexing_assignment_dict_already_exists(self):
df = pd.DataFrame({'x': [1, 2, 6],
'y': [2, 2, 8],
'z': [-5, 0, 5]}).set_index('z')
expected = df.copy()
rhs = dict(x=9, y=99)
df.loc[5] = rhs
expected.loc[5] = [9, 99]
tm.assert_frame_equal(df, expected)


class TestSeriesNoneCoercion(tm.TestCase):
EXPECTED_RESULTS = [
Expand Down

0 comments on commit d69fa3b

Please sign in to comment.