With SettingWithCopyWarning
, sometimes it refers you to the exact line of code in your module that triggered the warning (e.g. here) and other times it doesn't (e.g. here).
Short of going through each line of the code (doesn't sound too appealing if you're reviewing hundreds of lines of code), is there a way to pinpoint the line of code that triggered the warning assuming the warning does not return that information?
I wonder if this is a bug in the warning to return a warning without pinpointing the specific code that triggered it.
Warning (from warnings module):
File "C:\Python34\lib\site-packages\pandas\core\indexing.py", line 415
self.obj[item] = s
SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
Python 3.4, Pandas 0.15.0
You can have pandas raise SettingWithCopyError
instead of SettingWithCopyWarning
by setting the mode.chained_assignment
option to raise
instead of warn
.
import pandas as pd
pd.set_option('mode.chained_assignment', 'raise')
https://pandas.pydata.org/pandas-docs/stable/options.html#available-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With