Improve clarity around when SettingWithCopyWarning can be ignored (if ever?) · Issue #8730 · pandas-dev/pandas (original) (raw)

I [Edit: thought I got] a SettingWarningCopyWarning when running the following code:

frame[columnone][frame[columntwo]>x]=y

The docs seem to imply that I can safely ignore this error.

passed via reference (will stay)

In [273]: dfb['c'][dfb.a.str.startswith('o')] = 42

Is it therefore generally true that I can always ignore errors when the command I'm running is of the form:

frame[columnames][booleanconditiononframe]=x

I use this all the time, and I think it always works. If that's true, it would be great if it was specifically called out in a 'you can ignore this warning when...' section. If that's not true (e.g. it works for scalar x / numeric x but not for series x), it would be great if that were called out too.

Sorry if this seems trivial, but I'm trying to explain this to a colleague who's new to pandas and he's confused, and it looks like even old hands can be confused when confronted with this warning (see #6757).

[Edit: looking at his code again, I suspect the SettingWithCopy warning was from a different line of code - (I wish warnings made it clear where they were from). All the same, it would still be great if the docs could be clear if there are circumstances where you always get a reference rather than a copy]