Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SettingWithCopyWarning in Pandas 1.5.3 not working

I’m aware there are a few threads about this but I’m having trouble with the actual SettingWithCopyWarning itself so none of them are of any help.

I’ve recently nuked my machine and am in the process of reinstalling Pycharm and all the libraries etc. On running some of my scripts I keep getting an error to do with suppressing the SettingWithCopyWarning.

import warnings
from pandas.core.common import SettingWithCopyWarning
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)

These are the lines I’m running, and they result in the following error message:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ImportError: cannot import name 'SettingWithCopyWarning' from 'pandas.core.common'

I’ve looked at the common.py file and see no reference to the SettingWithCopyWarning. I’m using Python 3.8, and Pandas version 1.5.3.

Cheers

>Solution :

Use pandas.errors.SettingWithCopyWarning

import warnings
from pandas.errors import SettingWithCopyWarning
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)

I strongly discouraged you to hide this warning. This can have unexpected side effects and lead to errors

Take the time to read How to deal with SettingWithCopyWarning in Pandas

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading