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

df.fillna inplace bug #10342

Closed
vmirnv opened this issue Jun 12, 2015 · 3 comments
Closed

df.fillna inplace bug #10342

vmirnv opened this issue Jun 12, 2015 · 3 comments
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Usage Question

Comments

@vmirnv
Copy link

vmirnv commented Jun 12, 2015

This code:

a = df()
a['f'] = [None, None]
a['s'] = [None, None]
a['t'] = [None, None]
a.loc[:,['f','s']] = a.loc[:,['f','s']].fillna(-1) #works
a.loc[:,'f'].fillna(-1, inplace=True) #also works
a.loc[:,['f','s']].fillna(-1, inplace=True) #doesn't

It's not the biggest error, but still.

@shoyer
Copy link
Member

shoyer commented Jun 12, 2015

please showed actual and expected output

@vmirnv
Copy link
Author

vmirnv commented Jun 12, 2015

Should be like this:

    f   s   t
0   -1  -1  None
1   -1  -1  None

But instead after a.loc[:,['f','s']].fillna(-1, inplace=True) you get this:

    f   s   t
0   None    None    None
1   None    None    None

@jreback
Copy link
Contributor

jreback commented Jun 12, 2015

You are chained indexing, and operating on a copy (numpy is creating a copy here, for object type is often does this). See docs here

You should not use a chained inplace op, ever. It is pretty hard for pandas to detect this though.

Further, in general you should NOT be using object dtypes to represent numbers (which is what you get with None). NaN is the missing value marker.

In [20]: id(a.values.base)
Out[20]: 4430108432

# so this is a view
In [19]: id(a.loc[:,'f'].values.base)
Out[19]: 4430108432

# this is a copy
In [18]: id(a.loc[:,['f','s']].values.base)
Out[18]: 4431376592

@jreback jreback closed this as completed Jun 12, 2015
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Usage Question labels Jun 12, 2015
jreback added a commit to jreback/pandas that referenced this issue Jun 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Usage Question
Projects
None yet
Development

No branches or pull requests

3 participants