I am having a strange warning issue in python. I use a large code base with many modules, and I cannot create a small script that reproduces this problem, sorry there is no minimal example. Whenever a warning appears, the program treats it as an error and exits. This is not for a specific type of alert, it seems to be for all of them (at least RuntimeWarning, PendingDeprecationWarning and UserWarning). I cannot easily prevent warnings, this will require a large modification of the work of another person, and they are not a problem for the functionality of the code.
Here are some things I tried that did NOT work:
Command Line Flag -W
Checked that $ PYTHONWARNINGS is not installed
Make sure sys.warnoptions is empty
Foreword script with:
import warnings
warnings.filterwarnings("ignore")
I already used logging, changed the logging settings to:
logging.basicConfig(level=logging.DEBUG)
logging.captureWarnings(True)
Are there any real python gurus who can help?
EDIT:
The offender with whom I am having problems is dividing by zero. The correct behavior should return NaN (which will later be converted to zero). I have to use the decimal separator of the array for speed reasons, so breaking it in a loop is not viable. Here are two more things I tried, where arr2 contains zeros:
np.seterr(divide='ignore')
z = np.divide(arr1,arr2)
or
with np.errstate(divide='ignore'):
z = np.divide(arr1,arr2)
In both cases, I STILL gets RuntimeWarning, followed by the exit of the program.
EDIT AGAIN:
I found an offensive line of code, but I don't understand why this will cause this problem:
warnings.simplefilter("ignore",lineno=32)
If someone helps me explain this, it will be great.