-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
.ix[] inconsistently assigns right hand side #4508
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
Comments
you have a list on the rhs, so it MUST be assigned by position, you are MUCH better off using a series here (which exactly specify what the values align to) I'll look and see if there is a bug in any event |
This is from current master (FYI I did push a change about an hour ago, but had to do with Panel alignment) Looks ok to me
Also your very last assignment You should NEVER do this; it may accidently work, but its not a guarantee (and its very hard to warn aboutt his); this is a chained assignment |
Thank you very much - I guess it was a version-specific issue and it's best to update to the latest. I started doing "chained assignment" when I noticed the simple/combined assignment was not working properly. In my ignorance I actually thought it'd be more straightforward. |
np the chained assignment is a very touchy issue...everyone wants it to work, but python basically doesn't let you do in a nice clean way (well it doesn, but it doesn't let you have control of it!) and its insidous because it can work (I may have completely fixed it, but not 100% sure, so that we dont' official allow it) - and neither does numpy.... |
closing as already in master (tests are in #4509) |
This is with pandas 0.12.0.dev-be25266:
In [1]: import pandas as pd
In [2]: df = pd.DataFrame({'a':[1,2,3],'b':[0,1,2]})
In [3]: df.ix[[0,2,],'b'] = [100,-100] # Works as intended
In [4]: print df
a b
0 1 100
1 2 1
2 3 -100
In [6]: df = pd.DataFrame({'a':range(4)})
In [7]: df['b']=pd.np.nan
In [8]: df.ix[[1,3],'b'] = [100,-100] # Both rows get assigned 100
In [9]: print df
a b
0 0 NaN
1 1 100
2 2 NaN
3 3 100
In [10]: df['b'].ix[[1,3]] = [100,-100] # Works as intended
In [11]: print df
a b
0 0 NaN
1 1 100
2 2 NaN
3 3 -100
The text was updated successfully, but these errors were encountered: