pycaret / pycaret

An open-source, low-code machine learning library in Python
https://www.pycaret.org
MIT License
8.91k stars 1.77k forks source link

[BUG]: Allow Custom Logger Configuration to Handle Prophet Dependency Warning #3957

Open gabrown opened 7 months ago

gabrown commented 7 months ago

pycaret version checks

Issue Description

Time Series setup allows the passing of a logger object to be passed, and all pycaret messages would be routed to that logger. However just importing the TSForecastingExperiment creates either warning or info messages about the dependancy on prophet and as it as at import time, it is not routed to the logger. This prevents me from creating my own logger to catch and handle the message in the way I want.

This can be problematic in scenarios where we want to control how warnings are logged and displayed, especially in production environments where we might want to suppress certain warnings or redirect them to specific logging channels.

Reproducible Example

from pycaret.time_series import TSForecastingExperiment

Expected Behavior

I expect no logs and no logging file (logs.log) to be created

Actual Results

I get a logs.log file created with the following output:
2024-04-04 10:34:20,632:WARNING:
'prophet' is a soft dependency and not included in the pycaret installation. Please run: `pip install prophet` to install.
Or if prophet is already installed:
2024-04-04 10:36:26,374:INFO:Soft dependency imported: prophet: 1.1.5

Installed Versions

System: python: 3.10.6 (main, Jan 12 2024, 15:30:20) [Clang 15.0.0 (clang-1500.1.0.2.5)] executable: /Users/XXXXXX/work_projects/temp/venv/bin/python machine: macOS-14.4.1-arm64-arm-64bit PyCaret required dependencies: pip: 24.0 setuptools: 69.2.0 pycaret: 3.3.0 IPython: 8.23.0 ipywidgets: 8.1.2 tqdm: 4.66.2 numpy: 1.26.4 pandas: 2.1.4 jinja2: 3.1.3 scipy: 1.11.4 joblib: 1.3.2 sklearn: 1.4.1.post1 pyod: 1.1.3 imblearn: 0.12.2 category_encoders: 2.6.3 lightgbm: 4.3.0 numba: 0.59.1 requests: 2.31.0 matplotlib: 3.7.5 scikitplot: 0.3.7 yellowbrick: 1.5 plotly: 5.20.0 plotly-resampler: Not installed kaleido: 0.2.1 schemdraw: 0.15 statsmodels: 0.14.1 sktime: 0.26.0 tbats: 1.1.3 pmdarima: 2.0.4 psutil: 5.9.8 markupsafe: 2.1.5 pickle5: Not installed cloudpickle: 3.0.0 deprecation: 2.1.0 xxhash: 3.4.1 wurlitzer: 3.0.3 PyCaret optional dependencies: shap: Not installed interpret: Not installed umap: Not installed ydata_profiling: Not installed explainerdashboard: Not installed autoviz: Not installed fairlearn: Not installed deepchecks: Not installed xgboost: Not installed catboost: Not installed kmodes: Not installed mlxtend: Not installed statsforecast: Not installed tune_sklearn: Not installed ray: Not installed hyperopt: Not installed optuna: Not installed skopt: Not installed mlflow: Not installed gradio: Not installed fastapi: Not installed uvicorn: Not installed m2cgen: Not installed evidently: Not installed fugue: Not installed streamlit: Not installed prophet: Not installed
gabrown commented 7 months ago

Just some extra context for what seems to be causing the warning. I think it is the creation of the Patched class here. All the other model types only run the _check_soft_dependencies in the init of the model classes, and I guess this is only done during/after setup() has been called.