-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Possible spurious SettingWithCopyWarning #6757
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
Comments
master looks ok on these (no warnings) ....... IIRC 0.13.1 did have some false positives I don't get on 0.13.1 I am on numpy 1.7.1....that could be a factor.... |
Strange, I get these on
|
hmm...do you get them ALWAYS, even on a fresh ipython? |
Strange, first it seemed that I couldn't replicate this with a fresh ipython, but now it seems that I only see it if I first print the frame: If I run this on a fresh ipython, I get the warnings:
and with this not:
Although with the original code, this was certainly not the case (that it was first printed). And above was now with latest master ( |
hmm...ok I can replicate that It is legit because of : which is a sliced version of the original The problem is that you are reassigning
|
I also get the warning when assigning to a different variable (and then also without printing the frame first!):
But I suppose here the warning is legitimate, as it is indeed not changed in the original. |
that is legit |
ah, yes, was just updating my comment saying that. |
of course with the caveat that its not wrong per se, just a warning (mainly for new users). |
I get this when I do inplace sort_index and fillna: portfolio_analytics\attribution\Hierarchies.py:212: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame C:\Python27\lib\site-packages\pandas\core\generic.py:2174: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame |
Another one: C:\Python27\lib\site-packages\pandas\core\indexing.py:346: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. |
Wow! This thing is everywhere:
|
Read this: http://stackoverflow.com/questions/21463589/pandas-chained-assignments/21463854#21463854 once it happens, it will repeat in general (until you create a copy) don't do inplace ops |
Ok. In my last example, what am I doing inplace? |
it prob was already not a copy you need to look at the first time it happens |
It's a copy, yes. I wanted it explicitly just to make sure the original DataFrame is left intact.
|
and is that a series? |
DataFrame |
you need to use |
I'm getting similar warnings for an operation like this, where I am just trying to truncate a variable at a particular value:
So, I go in and try to use
But get the same error. The object
So, I tried to use Its not clear to me what is going on here. Running '0.14.1-486-g1d65bc8' on Python 2.7.6 and OS X 10.9.5. |
no, you are still chaining, you need to use
|
OK, I see now. Man, that's going to be a tough one for new users to digest. |
that's why its a warning! That's the reason for it though. It sometimes does work. (and has been around since 0.13.0), just getting better / less spurious though the versions. |
you should put But that's the rub, you don't want to have to care/know its a view (and if its a view, you certainly don't want to propogate back to the original, except explicity). |
closing as stale. pls reopen if still an issue. |
Found some
SettingWithCopyWarning
warnings in older code with newer pandas. But it's quite possible that these are just side-effects of the warning ('False positives') and it cannot easily be detected, but I am no expert in that field.Simplified dummy example:
Setting a value with
.loc[]
(this output is from master, in 0.13.1 I got even the advice toTry using .loc[row_index,col_indexer] = value instead
while I was using it ... in master just the warning):And then replacing a value with
replace
(also here the advice to use.loc
is a little bit strange I think):The text was updated successfully, but these errors were encountered: