|
2 | 2 | import unittest
|
3 | 3 | import nose
|
4 | 4 | import itertools
|
| 5 | +import warnings |
5 | 6 |
|
6 | 7 | from pandas.compat import range, lrange, StringIO, lmap, map
|
7 | 8 | from numpy import random, nan
|
@@ -954,6 +955,24 @@ def test_ix_assign_column_mixed(self):
|
954 | 955 | df.ix[df.x % 2 == 0, 'y'] = df.ix[df.x % 2 == 0, 'y'] * 100
|
955 | 956 | assert_frame_equal(df,expected)
|
956 | 957 |
|
| 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 | + |
957 | 976 | def test_iloc_mask(self):
|
958 | 977 |
|
959 | 978 | # GH 3631, iloc with a mask (of a series) should raise
|
@@ -985,7 +1004,6 @@ def test_iloc_mask(self):
|
985 | 1004 | ('locs','.iloc') : 'iLocation based boolean indexing on an integer type is not available',
|
986 | 1005 | }
|
987 | 1006 |
|
988 |
| - import warnings |
989 | 1007 | warnings.filterwarnings(action='ignore', category=UserWarning)
|
990 | 1008 | result = dict()
|
991 | 1009 | for idx in [None, 'index', 'locs']:
|
|
0 commit comments