From 9aec8fc751416acc8ff5b36a9472cac96a9e2ca8 Mon Sep 17 00:00:00 2001 From: Valeriy Khakhutskyy <1292899+valeriy42@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:26:11 +0100 Subject: [PATCH] Add deprecation warning for ESGradientBoostingModel subclasses (#738) Introduce a warning indicating that exporting data frame analytics models as ESGradientBoostingModel subclasses is deprecated and will be removed in version 9.0.0. The implementation of ESGradientBoostingModel relies on importing undocumented private classes that were changed in 1.4 to https://github.com/scikit-learn/scikit-learn/pull/26278. This dependency makes the code difficult to maintain, while the functionality is not widely used by users. Therefore, we will deprecate this functionality in 8.16 and remove it completely in 9.0.0. --------- Co-authored-by: Quentin Pradet --- eland/__init__.py | 7 ++++++- eland/common.py | 4 ++++ eland/ml/exporters/es_gb_models.py | 12 +++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/eland/__init__.py b/eland/__init__.py index f1a2b30..71e227b 100644 --- a/eland/__init__.py +++ b/eland/__init__.py @@ -15,6 +15,8 @@ # specific language governing permissions and limitations # under the License. +import warnings + from ._version import ( # noqa: F401 __author__, __author_email__, @@ -25,13 +27,16 @@ from ._version import ( # noqa: F401 __url__, __version__, ) -from .common import SortOrder +from .common import ElandDeprecationWarning, SortOrder from .dataframe import DataFrame from .etl import csv_to_eland, eland_to_pandas, pandas_to_eland from .index import Index from .ndframe import NDFrame from .series import Series +# Display Eland deprecation warnings by default +warnings.simplefilter("default", category=ElandDeprecationWarning) + __all__ = [ "DataFrame", "Series", diff --git a/eland/common.py b/eland/common.py index 219ec8b..667313c 100644 --- a/eland/common.py +++ b/eland/common.py @@ -52,6 +52,10 @@ PANDAS_VERSION: Tuple[int, ...] = tuple( _ELAND_MAJOR_VERSION = int(_eland_version.split(".")[0]) +class ElandDeprecationWarning(DeprecationWarning): + """Warning for deprecation functionality in Eland""" + + with warnings.catch_warnings(): warnings.simplefilter("ignore") EMPTY_SERIES_DTYPE = pd.Series().dtype diff --git a/eland/ml/exporters/es_gb_models.py b/eland/ml/exporters/es_gb_models.py index 5802b05..4f1e197 100644 --- a/eland/ml/exporters/es_gb_models.py +++ b/eland/ml/exporters/es_gb_models.py @@ -15,6 +15,7 @@ # specific language governing permissions and limitations # under the License. +import warnings from abc import ABC from typing import Any, List, Literal, Mapping, Optional, Set, Tuple, Union @@ -36,7 +37,7 @@ from sklearn.ensemble._gb_losses import ( from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor from sklearn.utils.validation import check_array -from eland.common import ensure_es_client +from eland.common import ElandDeprecationWarning, ensure_es_client from eland.ml.common import TYPE_CLASSIFICATION, TYPE_REGRESSION from ._sklearn_deserializers import Tree @@ -62,6 +63,10 @@ class ESGradientBoostingModel(ABC): model_id : str The unique identifier of the trained inference model in Elasticsearch. + Deprecation Warning: + ------ + Exporting data frame analytics models as ESGradientBoostingModel subclasses is deprecated and will be removed in version 9.0.0. + Raises ------ RuntimeError @@ -70,6 +75,11 @@ class ESGradientBoostingModel(ABC): The model is expected to be trained in Elastic Stack. Models initially imported from xgboost, lgbm, or sklearn are not supported. """ + warnings.warn( + "Exporting data frame analytics models as ESGradientBoostingModel subclasses is deprecated and will be removed in version 9.0.0.", + ElandDeprecationWarning, + stacklevel=2, + ) self.es_client: Elasticsearch = ensure_es_client(es_client) self.model_id = model_id