Skip to content

Commit 515074a

Browse files
committed
Merge pull request #4509 from jreback/ix_consist
TST: tests for GH4502, consistency in ix assignments, but ok in master
2 parents 2e09fcc + 3030c4d commit 515074a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pandas/tests/test_indexing.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import unittest
33
import nose
44
import itertools
5+
import warnings
56

67
from pandas.compat import range, lrange, StringIO, lmap, map
78
from numpy import random, nan
@@ -954,6 +955,24 @@ def test_ix_assign_column_mixed(self):
954955
df.ix[df.x % 2 == 0, 'y'] = df.ix[df.x % 2 == 0, 'y'] * 100
955956
assert_frame_equal(df,expected)
956957

958+
# GH 4508, making sure consistency of assignments
959+
df = DataFrame({'a':[1,2,3],'b':[0,1,2]})
960+
df.ix[[0,2,],'b'] = [100,-100]
961+
expected = DataFrame({'a' : [1,2,3], 'b' : [100,1,-100] })
962+
assert_frame_equal(df,expected)
963+
964+
df = pd.DataFrame({'a': lrange(4) })
965+
df['b'] = np.nan
966+
df.ix[[1,3],'b'] = [100,-100]
967+
expected = DataFrame({'a' : [0,1,2,3], 'b' : [np.nan,100,np.nan,-100] })
968+
assert_frame_equal(df,expected)
969+
970+
# ok, but chained assignments are dangerous
971+
df = pd.DataFrame({'a': lrange(4) })
972+
df['b'] = np.nan
973+
df['b'].ix[[1,3]] = [100,-100]
974+
assert_frame_equal(df,expected)
975+
957976
def test_iloc_mask(self):
958977

959978
# GH 3631, iloc with a mask (of a series) should raise
@@ -985,7 +1004,6 @@ def test_iloc_mask(self):
9851004
('locs','.iloc') : 'iLocation based boolean indexing on an integer type is not available',
9861005
}
9871006

988-
import warnings
9891007
warnings.filterwarnings(action='ignore', category=UserWarning)
9901008
result = dict()
9911009
for idx in [None, 'index', 'locs']:

0 commit comments

Comments
 (0)