Skip to content
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

assigning using df.loc and unsorted labels doesn't put values in the right places #6254

Closed
sadruddin opened this issue Feb 4, 2014 · 7 comments · Fixed by #6256
Closed
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@sadruddin
Copy link

Using 0.13.1 (gohlke binaries, Win64, using numpy 1.8):

When using .loc, when passing unsorted labels, pandas doesn't assign the values in the designed labels' locations. Example:
df = pandas.DataFrame(index=[3, 5, 4], columns=['A'])
df.loc[[4, 3, 5], 'A'] = [1, 2, 3]
Result is:

Out[30]: 
   A
3  1
5  2
4  3

One would have expected:

Out[30]: 
   A
3  2
5  3
4  1
@jreback
Copy link
Contributor

jreback commented Feb 4, 2014

yep....this slipped thru (was trying to fix another case)..

as a work around you can make the rhs a Series (with the correct indexes)

@jreback
Copy link
Contributor

jreback commented Feb 4, 2014

@sadruddin thanks for the report!

@sadruddin
Copy link
Author

And thank you for fixing bugs so quickly!
Side question, doesn't it make sense to release a 0.13.2 rather soon? I would say that this is not really a corner case bug that can wait 3-4 months to be fixed in official releases. What do you think?

@jreback
Copy link
Contributor

jreback commented Feb 7, 2014

this is a corner case
just make the rhs a Series

@sadruddin
Copy link
Author

The workaround is clear and simple, not arguing about that, I'm just saying that the likelihood of someone else getting caught by that is not small, especially given that it doesn't raise any error or warning, but just silently misplaces the elements

@jreback
Copy link
Contributor

jreback commented Feb 7, 2014

it's a really small corner case and require that the entire column be replaced
u are welcome to use master of even pull the fix and update your local install your self
your was the first time this bug report was raised

0.14 is the next release Ann is soon

@dieterv77
Copy link
Contributor

I think i ran into a related bug (at least i ran into it with 0.13.1, but seems fixed with master):

import pandas
import numpy as np
x = pandas.DataFrame(np.random.randn(3,3))
y = pandas.DataFrame(np.random.randn(3,3),index=[2,0,1],columns=[0,1,2])
x.ix[y.index,y.columns] = y
print np.linalg.norm(y - x)

this will print a nonzero value, but it shouldn't.
The only workaround i see would be to reindex y, but in the actual application, sometimes y is a submatrix (in which case the bug doesn't trigger).

Just wanted to add this data point, in case it can be used to motivate a 0.13.2 bugfix release.

thanks very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants