I believe this question was raised lots of times already but I have a specific use case where I can't solve the issue with many of the methods described on the web.
In one of my projects, I am using joblib library, and it shows DeprecationWarning because it uses imp library somewhere internally:
from sklearn.externals.joblib import Parallel, delayed
def main():
    xs = Parallel()(delayed(lambda x: x**2)(i) for i in range(1, 6))
    print(sum(xs))
if __name__ == '__main__':
    main()
I am trying to filter out warning with interpreter option -W but it doesn't help:
$ python -W ignore example.py                                                                                                                   
[...]/lib/python3.7/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47:
DeprecationWarning: the imp module is deprecated in favour of importlib; 
see the module's documentation for alternative uses import imp
55
Also, I was trying an explicit filtering using warnings module but it is not helping also:
import warnings
warnings.simplefilter('ignore', category=DeprecationWarning)
from sklearn.externals.joblib import Parallel, delayed
def main():
    xs = Parallel()(delayed(lambda x: x**2)(i) for i in range(1, 6))
    print(sum(xs))
if __name__ == '__main__':
    main()
I had similar issues with matplotlib module and some other third-party libraries.  Probably there are some other ways (i.e., env vars) but I don't understand why these solutions don't work. 
Could anyone explain how the warnings system actually works in Python? It is possible that third-party libraries intentionally override client's warnings settings? I would say that this question is one of the most obscure topics for me.
 
     
    