Closed
Description
Hi there,
this is one that has puzzled me for quite some time, but somehow it never asked about it. It seems whether an conditional assignment to a df column is performed or not depends on the order of indexing / member getting inside the left-hand expression of the assignment statement. See this snippet:
import pandas as pd
# create some data
data = {'foo': list('abcde'),
'bar': range(5)}
df = pd.DataFrame(data)
# create arbitrary index.
my_idx = df.bar > 2
print df[my_idx]
# assign to a member which was accessed after indexing.
df[my_idx].foo = 'X'
# see there is no change
print df
# assign to member which was accessed before indexing.
df.foo[my_idx] = 'X'
# now it has worked
print df
Is there a deliberate reason for this behaviour? My feeling about this is that it may confuse new users and may be hard to track down, as this goes silently and looks like correct code.