How can I define and access <sub> classes under pandas?

I am trying to eliminate this widely discussed pandas warning .

When trying to determine the location (although I'm also interested in how to do this at all), I want to configure warnings.simplefilter to an error only when setting upWithCopyWarning .

I'm trying to:

import warnings
warnings.simplefilter("error", SettingWithCopyWarning)

This does not work because the interpreter does not know what SettingWithCopyWarning is. I assume this is a warning sublayer created by pandas, but I'm not sure how to properly configure this filter (or how to access the class directly).

For an additional warning color (in the latest versions of python or pandas, you don’t know where the change was made). Tell you the location, but in this case it happens in the pandas kernel code:

/path/to/my/virtualenv/lib/python2.7/site-packages/pandas/core/indexing.py:426: 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 caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self.obj[item] = s

I need to see the entire trace to find out what caused the pandas call, which ultimately caused this warning, so my desire is to get an error.

Thanks for helping me figure out how to identify this warning.

+1
source share
1 answer

You need to specify the exact location:

import pandas as pd
import warnings
warnings.simplefilter("error", pd.core.common.SettingWithCopyWarning)
+1
source

Source: https://habr.com/ru/post/1589388/


All Articles