Skip to content

Indexing problem with in-place operator #8511

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

Closed
dieterv77 opened this issue Oct 8, 2014 · 2 comments · Fixed by #8520
Closed

Indexing problem with in-place operator #8511

dieterv77 opened this issue Oct 8, 2014 · 2 comments · Fixed by #8520
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@dieterv77
Copy link
Contributor

Hi, thanks to all of you who spend time on this project, it is invaluable to me.
Unfortuatnely, i think I have run into an indexing-type issue, either that or my expectations are incorrect. Consider the following script:

import random
import pandas
import numpy as np

columns = list('abcdefg')
subcols = columns[1:-1]
X = pandas.DataFrame(0.0, columns=columns, index=range(100))
Z = pandas.DataFrame(np.random.randn(100,len(subcols)), columns=subcols, index=range(100))
block1 = list(subcols)
random.shuffle(block1)

X[block1] -= Z
print X.corrwith(Z)

X = pandas.DataFrame(0.0, columns=columns, index=range(100))
X[block1] -= Z[block1]
print X.corrwith(Z)

print pandas.__version__

The output i get is something like this (obviously depends on the random inputs)
a NaN
b -0.127386
c -0.073521
d -0.073521
e -0.127386
f -1.000000
g NaN
dtype: float64
a NaN
b -1
c -1
d -1
e -1
f -1
g NaN
dtype: float64
0.15.0rc1-10-g215569a

where the second result is what i would have expected.
I was surprised to find that I have to "reindex" Z by block1 to get a correct result. Is my expectation incorrect?

Many thanks

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Oct 8, 2014
@jreback jreback added this to the 0.15.0 milestone Oct 8, 2014
@jreback
Copy link
Contributor

jreback commented Oct 8, 2014

yep, something going on here.

@jreback
Copy link
Contributor

jreback commented Oct 9, 2014

@dieterv77 #8511 fixes this (and an odd aliasing bug).

Was a bit tricky acutally. We were defining __iadd__ == __add__ which normally is just fine.
The args are aligned properly and such. But python then does a __setitem__ with the original key (which is in a different order), and the aligning code couldn't intecept this. Adding __i*__ methods fixes this properly (and solves another aliasing issue from a while back, #5104)

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.

2 participants