I want to suppress a specific type of warning using regular expression. The warning message is:
C:\Anaconda3\lib\site-packages\pandas\core\indexing.py:420: 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
My way of suppressing filter:
import warnings
warnings.filterwarnings("ignore", message= ".*A value is trying to.*")
However, it failed. I did try pasting different part of the warning message into the regex but still failed. I want to know why.
Your regular expression does not match the correct message string.
r".*A Value is trying to.*"
does not match "\nA value is trying to be.*"
because r"."
matches everything except the newline character.
Sometimes it can be tricky to figure out what the actual message string is without looking at the source code of the module that generated the warning.
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