kedro-org / kedro

Kedro is a toolbox for production-ready data science. It uses software engineering best practices to help you create data engineering and data science pipelines that are reproducible, maintainable, and modular.
https://kedro.org
Apache License 2.0
9.91k stars 900 forks source link

Prevent logging at the kedro project level #2184

Closed matheus695p closed 1 year ago

matheus695p commented 1 year ago

I'm seeing a number of warnings of the type below but I can't seem to figure out how to stop kedro from logging these to std console

thought the snippet below might work if I add it to the cli.py but it didnt' do the job.. What do I seem to be missing here? /envs/kedro_test/lib/python3.7/site-packages/sklearn/linear_model/_least_angle.py:34: DeprecationWarning:np.floatis a deprecated alias for the builtinfloat. To silence this warning, usefloatby itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.float64here.

import warnings
# Added because the numpy and sklearn versions class for np.bool type of checks, see below
warnings.filterwarnings("ignore", category=DeprecationWarning,
                        # module="numpy|sklearn|mlflow",
                        message="is a deprecated alias for the builtin")
Warning control on a specific function, module is pretty straightforward. However, this deprecation warning is completely taking over the log file so that we can't see anything else.

Do you have suggestions where to place these warning filters, in versions later than 0.18 it is not possible to disable external warnings as proposed in this issue https://github.com/kedro-org/kedro/issues/737

lamhm commented 1 year ago

I have added the following lines into settings.py. They seem to work.

import warnings

warnings.simplefilter("ignore", category=DeprecationWarning)
matheus695p commented 1 year ago

@lamhm, I had already tried it, but it doesn't work with kedro versions higher than 0.18

antonymilne commented 1 year ago

I have just tried this out on Kedro 0.18.4 and can confirm that @lamhm's solution works and is the one I'd recommend. If it's not working for you then there must be something else in your setup that's causing the problem (e.g. some plugin, library or code in your project interfering somehow). Getting logging to work as you wish in Python is notoriously fiddly and temperamental I'm afraid.

Here's another option if the above doesn't work. It's more aggressive than the above solution because they will silence not just DeprecationWarnings but any warnings raised by warnings.warn (logging.warnings will still get through though, which is probably what you want). Add the following lines to settings.py:

import logging
logging.getLogger("py.warnings").setLevel(logging.ERROR)
AhdraMeraliQB commented 1 year ago

Hi @matheus695p, did the comment above resolve the issue, or will this need further investigation?

merelcht commented 1 year ago

I'll close this issue for now. If you @matheus695p, or anyone else still faces problems with logging at the kedro project level, feel free to re-open! 🙂