Skip to content

BUG: bug in chained assignment with ix and another chained series (GH5928) #5930

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
Jan 14, 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 @@ -88,6 +88,7 @@ Bug Fixes
- Bug in fully reindexing a Panel (:issue:`5905`)
- Bug in idxmin/max with object dtypes (:issue:`5914`)
- Bug in ``BusinessDay`` when adding n days to a date not on offset when n>5 and n%5==0 (:issue:`5890`)
- Bug in assigning to chained series with a series via ix (:issue:`5928`)

pandas 0.13.0
-------------
Expand Down
10 changes: 7 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def can_do_equal_len():

def _align_series(self, indexer, ser):
# indexer to assign Series can be tuple, slice, scalar
if isinstance(indexer, slice):
if isinstance(indexer, (slice, np.ndarray, list)):
indexer = tuple([indexer])

if isinstance(indexer, tuple):
Expand Down Expand Up @@ -453,8 +453,12 @@ def _align_series(self, indexer, ser):
all([com._is_sequence(_) for _ in indexer])):
ser = ser.reindex(obj.axes[0][indexer[0].ravel()],
copy=True).values
l = len(indexer[1].ravel())
ser = np.tile(ser, l).reshape(l, -1).T

# single indexer
if len(indexer) > 1:
l = len(indexer[1].ravel())
ser = np.tile(ser, l).reshape(l, -1).T

return ser

for i, idx in enumerate(indexer):
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,20 @@ def test_loc_setitem(self):
expected = Series([1,1,0],index=[4,5,6])
assert_series_equal(s, expected)

# GH 5928
# chained indexing assignment
df = DataFrame({'a' : [0,1,2] })
expected = df.copy()
expected.ix[[0,1,2],'a'] = -expected.ix[[0,1,2],'a']

df['a'].ix[[0,1,2]] = -df['a'].ix[[0,1,2]]
assert_frame_equal(df,expected)

df = DataFrame({'a' : [0,1,2], 'b' :[0,1,2] })
df['a'].ix[[0,1,2]] = -df['a'].ix[[0,1,2]].astype('float64') + 0.5
expected = DataFrame({'a' : [0.5,-0.5,-1.5], 'b' : [0,1,2] })
assert_frame_equal(df,expected)

def test_loc_getitem_int(self):

# int label
Expand Down