Skip to content

Indexing problem with in-place operator #8511

Closed
@dieterv77

Description

@dieterv77

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions