From 27717eead17470b945beabebc148010e0cc8543d Mon Sep 17 00:00:00 2001 From: "P. Sai Vinay" <33659563+V1NAY8@users.noreply.github.com> Date: Mon, 4 Jan 2021 20:20:45 +0100 Subject: [PATCH] Remove deprecated options and aliases --- README.md | 4 +- .../reference/api/eland.DataFrame.es_info.rst | 4 - .../reference/api/eland.Series.es_info.rst | 4 - eland/__init__.py | 4 +- eland/dataframe.py | 6 +- eland/etl.py | 36 ------ eland/index.py | 6 - eland/ml/__init__.py | 7 +- eland/ml/ml_model.py | 22 +--- eland/series.py | 6 +- ...odel_pytest.py => test_ml_model_pytest.py} | 120 ++---------------- 11 files changed, 21 insertions(+), 198 deletions(-) rename tests/ml/{test_imported_ml_model_pytest.py => test_ml_model_pytest.py} (80%) diff --git a/README.md b/README.md index 9fb6418..8268be0 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ to be serialized and used as an inference model in Elasticsearch ```python >>> from xgboost import XGBClassifier ->>> from eland.ml import ImportedMLModel +>>> from eland.ml import MLModel # Train and exercise an XGBoost ML model locally >>> xgb_model = XGBClassifier(booster="gbtree") @@ -163,7 +163,7 @@ to be serialized and used as an inference model in Elasticsearch [0 1 1 0 1 0 0 0 1 0] # Import the model into Elasticsearch ->>> es_model = ImportedMLModel( +>>> es_model = MLModel( es_client="localhost:9200", model_id="xgb-classifier", model=xgb_model, diff --git a/docs/sphinx/reference/api/eland.DataFrame.es_info.rst b/docs/sphinx/reference/api/eland.DataFrame.es_info.rst index caa8f77..c8ec319 100644 --- a/docs/sphinx/reference/api/eland.DataFrame.es_info.rst +++ b/docs/sphinx/reference/api/eland.DataFrame.es_info.rst @@ -3,8 +3,4 @@ eland.DataFrame.es_info .. currentmodule:: eland -.. warning:: - Previously this method was named ``info_es()``. - DataFrame.info_es() is deprecated, use DataFrame.es_info() instead. - .. automethod:: DataFrame.es_info diff --git a/docs/sphinx/reference/api/eland.Series.es_info.rst b/docs/sphinx/reference/api/eland.Series.es_info.rst index ade3c24..6a4747f 100644 --- a/docs/sphinx/reference/api/eland.Series.es_info.rst +++ b/docs/sphinx/reference/api/eland.Series.es_info.rst @@ -3,8 +3,4 @@ eland.Series.es_info .. currentmodule:: eland -.. warning:: - Previously this method was named ``info_es()``. - Series.info_es() is deprecated, use Series.es_info() instead. - .. automethod:: Series.es_info diff --git a/eland/__init__.py b/eland/__init__.py index 640b18a..f1a2b30 100644 --- a/eland/__init__.py +++ b/eland/__init__.py @@ -27,7 +27,7 @@ from ._version import ( # noqa: F401 ) from .common import SortOrder from .dataframe import DataFrame -from .etl import csv_to_eland, eland_to_pandas, pandas_to_eland, read_csv, read_es +from .etl import csv_to_eland, eland_to_pandas, pandas_to_eland from .index import Index from .ndframe import NDFrame from .series import Series @@ -40,7 +40,5 @@ __all__ = [ "pandas_to_eland", "eland_to_pandas", "csv_to_eland", - "read_csv", - "read_es", "SortOrder", ] diff --git a/eland/dataframe.py b/eland/dataframe.py index 7578a4f..369214f 100644 --- a/eland/dataframe.py +++ b/eland/dataframe.py @@ -39,7 +39,7 @@ from eland.filter import BooleanFilter from eland.groupby import DataFrameGroupBy from eland.ndframe import NDFrame from eland.series import Series -from eland.utils import deprecated_api, is_valid_attr_name +from eland.utils import is_valid_attr_name class DataFrame(NDFrame): @@ -628,10 +628,6 @@ class DataFrame(NDFrame): return buf.getvalue() - @deprecated_api("eland.DataFrame.es_info()") - def info_es(self): - return self.es_info() - def es_match( self, text: str, diff --git a/eland/etl.py b/eland/etl.py index 8f5cf87..8dc3fee 100644 --- a/eland/etl.py +++ b/eland/etl.py @@ -27,37 +27,6 @@ from pandas.io.parsers import _c_parser_defaults # type: ignore from eland import DataFrame from eland.common import DEFAULT_CHUNK_SIZE, ensure_es_client from eland.field_mappings import FieldMappings, verify_mapping_compatibility -from eland.utils import deprecated_api - - -@deprecated_api("eland.DataFrame()") -def read_es( - es_client: Union[str, List[str], Tuple[str, ...], Elasticsearch], - es_index_pattern: str, -) -> DataFrame: - """ - Utility method to create an eland.Dataframe from an Elasticsearch index_pattern. - (Similar to pandas.read_csv, but source data is an Elasticsearch index rather than - a csv file) - - Parameters - ---------- - es_client: Elasticsearch client argument(s) - - elasticsearch-py parameters or - - elasticsearch-py instance - es_index_pattern: str - Elasticsearch index pattern - - Returns - ------- - eland.DataFrame - - See Also - -------- - eland.pandas_to_eland: Create an eland.Dataframe from pandas.DataFrame - eland.eland_to_pandas: Create a pandas.Dataframe from eland.DataFrame - """ - return DataFrame(es_client=es_client, es_index_pattern=es_index_pattern) def pandas_to_eland( @@ -552,8 +521,3 @@ def csv_to_eland( # type: ignore # Now create an eland.DataFrame that references the new index return DataFrame(es_client, es_index_pattern=es_dest_index) - - -@deprecated_api("eland.csv_to_eland()") -def read_csv(*args, **kwargs) -> DataFrame: # type: ignore - return csv_to_eland(*args, **kwargs) diff --git a/eland/index.py b/eland/index.py index 3a130ad..afc6dfb 100644 --- a/eland/index.py +++ b/eland/index.py @@ -17,8 +17,6 @@ from typing import TYPE_CHECKING, Optional, TextIO -from eland.utils import deprecated_api - if TYPE_CHECKING: from .query_compiler import QueryCompiler @@ -95,7 +93,3 @@ class Index: buf.write("Index:\n") buf.write(f" es_index_field: {self.es_index_field}\n") buf.write(f" is_source_field: {self.is_source_field}\n") - - @deprecated_api("eland.Index.es_info()") - def info_es(self, buf: TextIO) -> None: - self.es_info(buf) diff --git a/eland/ml/__init__.py b/eland/ml/__init__.py index 3b65062..e8c2d43 100644 --- a/eland/ml/__init__.py +++ b/eland/ml/__init__.py @@ -15,9 +15,6 @@ # specific language governing permissions and limitations # under the License. -from eland.ml.ml_model import ImportedMLModel, MLModel +from eland.ml.ml_model import ImportedMLModel, MLModel # noqa: F401 -__all__ = [ - "MLModel", - "ImportedMLModel", -] +__all__ = ["MLModel"] diff --git a/eland/ml/ml_model.py b/eland/ml/ml_model.py index bdd1130..ff0e615 100644 --- a/eland/ml/ml_model.py +++ b/eland/ml/ml_model.py @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. -import warnings from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, cast import elasticsearch @@ -105,7 +104,7 @@ class MLModel: -------- >>> from sklearn import datasets >>> from xgboost import XGBRegressor - >>> from eland.ml import ImportedMLModel + >>> from eland.ml import MLModel >>> # Train model >>> training_data = datasets.make_classification(n_features=6, random_state=0) @@ -254,7 +253,6 @@ class MLModel: classification_labels: Optional[List[str]] = None, classification_weights: Optional[List[float]] = None, es_if_exists: Optional[str] = None, - overwrite: Optional[bool] = None, es_compress_model_definition: bool = True, ) -> "MLModel": """ @@ -318,9 +316,6 @@ class MLModel: - fail: Raise a Value Error - replace: Overwrite existing model - overwrite: **DEPRECATED** - bool - Delete and overwrite existing model (if exists) - es_compress_model_definition: bool If True will use 'compressed_definition' which uses gzipped JSON instead of raw JSON to reduce the amount of data sent @@ -370,20 +365,7 @@ class MLModel: serializer = transformer.transform() model_type = transformer.model_type - # Verify if both parameters are given - if overwrite is not None and es_if_exists is not None: - raise ValueError( - "Using 'overwrite' and 'es_if_exists' together is invalid, use only 'es_if_exists'" - ) - - if overwrite is not None: - warnings.warn( - "'overwrite' parameter is deprecated, use 'es_if_exists' instead", - DeprecationWarning, - stacklevel=2, - ) - es_if_exists = "replace" if overwrite else "fail" - elif es_if_exists is None: + if es_if_exists is None: es_if_exists = "fail" ml_model = MLModel( diff --git a/eland/series.py b/eland/series.py index 020fb67..31a7fe7 100644 --- a/eland/series.py +++ b/eland/series.py @@ -59,7 +59,7 @@ from eland.filter import ( ScriptFilter, ) from eland.ndframe import NDFrame -from eland.utils import deprecated_api, to_list +from eland.utils import to_list if TYPE_CHECKING: # type: ignore from elasticsearch import Elasticsearch # noqa: F401 @@ -712,10 +712,6 @@ class Series(NDFrame): return buf.getvalue() - @deprecated_api("eland.Series.es_info()") - def info_es(self) -> str: - return self.es_info() - def __add__(self, right): """ Return addition of series and right, element-wise (binary operator add). diff --git a/tests/ml/test_imported_ml_model_pytest.py b/tests/ml/test_ml_model_pytest.py similarity index 80% rename from tests/ml/test_imported_ml_model_pytest.py rename to tests/ml/test_ml_model_pytest.py index 24e5d9b..d1be910 100644 --- a/tests/ml/test_imported_ml_model_pytest.py +++ b/tests/ml/test_ml_model_pytest.py @@ -80,7 +80,7 @@ def check_prediction_equality(es_model, py_model, test_data): np.testing.assert_almost_equal(test_results, es_results, decimal=2) -class TestImportedMLModel: +class TestMLModel: @requires_no_ml_extras def test_import_ml_model_when_dependencies_are_not_available(self): from eland.ml import MLModel # noqa: F401 @@ -239,6 +239,17 @@ class TestImportedMLModel: es_model, regressor, random_rows(training_data[0], 20) ) + match = f"Trained machine learning model {model_id} already exists" + with pytest.raises(ValueError, match=match): + MLModel.import_model( + ES_TEST_CLIENT, + model_id, + regressor, + feature_names, + es_if_exists="fail", + es_compress_model_definition=compress_model_definition, + ) + # Clean up es_model.delete_model() @@ -460,110 +471,3 @@ class TestImportedMLModel: # Clean up es_model.delete_model() - - # If both overwrite and es_if_exists is given. - @requires_sklearn - @pytest.mark.parametrize("compress_model_definition", [True, False]) - @pytest.mark.parametrize("es_if_exists", ["fail", "replace"]) - @pytest.mark.parametrize("overwrite", [True, False]) - def test_imported_mlmodel_bothparams( - self, compress_model_definition, es_if_exists, overwrite - ): - # Train model - training_data = datasets.make_regression(n_features=5) - regressor = RandomForestRegressor() - regressor.fit(training_data[0], training_data[1]) - - feature_names = ["f0", "f1", "f2", "f3", "f4"] - model_id = "test_random_forest_regressor" - - match = "Using 'overwrite' and 'es_if_exists' together is invalid, use only 'es_if_exists'" - with pytest.raises(ValueError, match=match): - MLModel.import_model( - ES_TEST_CLIENT, - model_id, - regressor, - feature_names, - es_if_exists=es_if_exists, - overwrite=overwrite, - es_compress_model_definition=compress_model_definition, - ) - - # Deprecation warning for overwrite parameter - @requires_sklearn - @pytest.mark.parametrize("compress_model_definition", [True, False]) - @pytest.mark.parametrize("overwrite", [True]) - def test_imported_mlmodel_overwrite_true( - self, compress_model_definition, overwrite - ): - # Train model - training_data = datasets.make_regression(n_features=5) - regressor = RandomForestRegressor() - regressor.fit(training_data[0], training_data[1]) - - feature_names = ["f0", "f1", "f2", "f3", "f4"] - model_id = "test_random_forest_regressor" - - match = "'overwrite' parameter is deprecated, use 'es_if_exists' instead" - with pytest.warns(DeprecationWarning, match=match): - MLModel.import_model( - ES_TEST_CLIENT, - model_id, - regressor, - feature_names, - overwrite=overwrite, - es_compress_model_definition=compress_model_definition, - ) - - @requires_sklearn - @pytest.mark.parametrize("compress_model_definition", [True, False]) - @pytest.mark.parametrize("overwrite", [False]) - def test_imported_mlmodel_overwrite_false( - self, compress_model_definition, overwrite - ): - # Train model - training_data = datasets.make_regression(n_features=5) - regressor = RandomForestRegressor() - regressor.fit(training_data[0], training_data[1]) - - feature_names = ["f0", "f1", "f2", "f3", "f4"] - model_id = "test_random_forest_regressor" - - match_error = f"Trained machine learning model {model_id} already exists" - match_warning = ( - "'overwrite' parameter is deprecated, use 'es_if_exists' instead" - ) - with pytest.raises(ValueError, match=match_error): - with pytest.warns(DeprecationWarning, match=match_warning): - MLModel.import_model( - ES_TEST_CLIENT, - model_id, - regressor, - feature_names, - overwrite=overwrite, - es_compress_model_definition=compress_model_definition, - ) - - # Raise ValueError if Model exists when es_if_exists = 'fail' - @requires_sklearn - @pytest.mark.parametrize("compress_model_definition", [True, False]) - def test_es_if_exists_fail(self, compress_model_definition): - # Train model - training_data = datasets.make_regression(n_features=5) - regressor = RandomForestRegressor() - regressor.fit(training_data[0], training_data[1]) - - feature_names = ["f0", "f1", "f2", "f3", "f4"] - model_id = "test_random_forest_regressor" - - # If both overwrite and es_if_exists is given. - match = f"Trained machine learning model {model_id} already exists" - with pytest.raises(ValueError, match=match): - MLModel.import_model( - ES_TEST_CLIENT, - model_id, - regressor, - feature_names, - es_if_exists="fail", - es_compress_model_definition=compress_model_definition, - )