diff --git a/mlflow/statsmodels.py b/mlflow/statsmodels.py index 11aed3a49e83c..407b2a554aa48 100644 --- a/mlflow/statsmodels.py +++ b/mlflow/statsmodels.py @@ -377,7 +377,7 @@ def _get_autolog_metrics(fitted_model): if len(failed_evaluating_metrics) > 0: _logger.warning( - f"Failed to autolog metrics: {', '.join(sorted(failed_evaluating_metrics))}" + f"Failed to autolog metrics: {', '.join(sorted(failed_evaluating_metrics))}." ) return result_metrics diff --git a/tests/statsmodels/test_statsmodels_autolog.py b/tests/statsmodels/test_statsmodels_autolog.py index 1929372abee31..57e96063cc68c 100644 --- a/tests/statsmodels/test_statsmodels_autolog.py +++ b/tests/statsmodels/test_statsmodels_autolog.py @@ -5,7 +5,6 @@ from statsmodels.tsa.base.tsa_model import TimeSeriesModel import mlflow import mlflow.statsmodels -from mlflow.utils.file_utils import TempDir from tests.statsmodels.model_fixtures import ( arma_model, ols_model, @@ -120,6 +119,26 @@ def test_statsmodels_autolog_logs_basic_metrics(): metrics = run.data.metrics assert set(metrics.keys()) == set(mlflow.statsmodels._autolog_metric_allowlist) + @property + def metric_raise_error(self): + raise RuntimeError() + + class MockSummary: + def as_text(self): + return "mock summary." + + with mock.patch( + "statsmodels.regression.linear_model.OLSResults.f_pvalue", metric_raise_error + ), mock.patch( + "statsmodels.regression.linear_model.OLSResults.fvalue", metric_raise_error + ), mock.patch( + "statsmodels.regression.linear_model.OLSResults.summary", lambda _: MockSummary() + ), mock.patch( + "mlflow.statsmodels._logger.warning" + ) as mock_warning: + ols_model() + mock_warning.assert_called_once_with("Failed to autolog metrics: f_pvalue, fvalue.") + def test_statsmodels_autolog_works_after_exception(): mlflow.statsmodels.autolog()