From d1912bf046b2f4c03a7872411b404dd59e70e27e Mon Sep 17 00:00:00 2001 From: kalyanr Date: Tue, 13 Feb 2024 00:10:47 +0530 Subject: [PATCH] lint fixes Signed-off-by: kalyanr --- docs/source/conf.py | 1 - opensearch_py_ml/dataframe.py | 6 ++++-- opensearch_py_ml/field_mappings.py | 6 +++--- opensearch_py_ml/ml_commons/model_uploader.py | 6 +++--- .../ml_models/metrics_correlation/event_detection.py | 6 +++--- opensearch_py_ml/ml_models/sentencetransformermodel.py | 6 +++--- opensearch_py_ml/operations.py | 8 +++++--- tests/dataframe/test_iterrows_itertuples_pytest.py | 8 +++++--- utils/model_uploader/update_models_upload_history_md.py | 6 +++--- 9 files changed, 29 insertions(+), 24 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 63fc48e9d..ea1c70897 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -22,7 +22,6 @@ import os import sys - sys.path.insert(0, os.path.abspath("../../")) # -- Project information ----------------------------------------------------- diff --git a/opensearch_py_ml/dataframe.py b/opensearch_py_ml/dataframe.py index cee1acc88..64772887f 100644 --- a/opensearch_py_ml/dataframe.py +++ b/opensearch_py_ml/dataframe.py @@ -978,8 +978,10 @@ def _sizeof_fmt(num: float, size_qualifier: str) -> str: elif verbose is False: # specifically set to False, not nesc None _non_verbose_repr() else: - _non_verbose_repr() if exceeds_info_cols else _verbose_repr( - number_of_columns + ( + _non_verbose_repr() + if exceeds_info_cols + else _verbose_repr(number_of_columns) ) # pandas 0.25.1 uses get_dtype_counts() here. This diff --git a/opensearch_py_ml/field_mappings.py b/opensearch_py_ml/field_mappings.py index b3c83914a..75bbd1833 100644 --- a/opensearch_py_ml/field_mappings.py +++ b/opensearch_py_ml/field_mappings.py @@ -445,9 +445,9 @@ def find_aggregatable(row, df): try: series = df.loc[df.os_field_name == os_field_name_keyword] if not series.empty and series.is_aggregatable.squeeze(): - row_as_dict[ - "aggregatable_os_field_name" - ] = os_field_name_keyword + row_as_dict["aggregatable_os_field_name"] = ( + os_field_name_keyword + ) else: row_as_dict["aggregatable_os_field_name"] = None except KeyError: diff --git a/opensearch_py_ml/ml_commons/model_uploader.py b/opensearch_py_ml/ml_commons/model_uploader.py index af7af2f62..850f6a80a 100644 --- a/opensearch_py_ml/ml_commons/model_uploader.py +++ b/opensearch_py_ml/ml_commons/model_uploader.py @@ -95,9 +95,9 @@ def _register_model( model_meta_json[TOTAL_CHUNKS_FIELD] = total_num_chunks if MODEL_CONTENT_SIZE_IN_BYTES_FIELD not in model_meta_json: - model_meta_json[ - MODEL_CONTENT_SIZE_IN_BYTES_FIELD - ] = model_content_size_in_bytes + model_meta_json[MODEL_CONTENT_SIZE_IN_BYTES_FIELD] = ( + model_content_size_in_bytes + ) if MODEL_CONTENT_HASH_VALUE not in model_meta_json: # Generate the sha1 hash for the model zip file hash_val_model_file = _generate_model_content_hash_value(model_path) diff --git a/opensearch_py_ml/ml_models/metrics_correlation/event_detection.py b/opensearch_py_ml/ml_models/metrics_correlation/event_detection.py index f9395d1a4..f6e5187cd 100644 --- a/opensearch_py_ml/ml_models/metrics_correlation/event_detection.py +++ b/opensearch_py_ml/ml_models/metrics_correlation/event_detection.py @@ -94,9 +94,9 @@ def merge_events( send = ends[ix] sevents = candidates[ix, :] - merged: List[ - Dict[str, torch.Tensor] - ] = [] # merge in linear pass over time dimension + merged: List[Dict[str, torch.Tensor]] = ( + [] + ) # merge in linear pass over time dimension currstart = torch.tensor([-1]) currend = torch.tensor([-1]) currevent = torch.ones(T) * -1.0 diff --git a/opensearch_py_ml/ml_models/sentencetransformermodel.py b/opensearch_py_ml/ml_models/sentencetransformermodel.py index db5d5a226..10f1174b5 100644 --- a/opensearch_py_ml/ml_models/sentencetransformermodel.py +++ b/opensearch_py_ml/ml_models/sentencetransformermodel.py @@ -1304,9 +1304,9 @@ def make_model_config_json( model_config_content["model_content_size_in_bytes"] = os.stat( model_zip_file_path ).st_size - model_config_content[ - "model_content_hash_value" - ] = _generate_model_content_hash_value(model_zip_file_path) + model_config_content["model_content_hash_value"] = ( + _generate_model_content_hash_value(model_zip_file_path) + ) if verbose: print("generating ml-commons_model_config.json file...\n") diff --git a/opensearch_py_ml/operations.py b/opensearch_py_ml/operations.py index 129a33ecf..c3d01e9e6 100644 --- a/opensearch_py_ml/operations.py +++ b/opensearch_py_ml/operations.py @@ -1159,9 +1159,11 @@ def _map_pd_aggs_to_os_aggs( # piggy-back on that single aggregation. if extended_stats_calls >= 2: os_aggs = [ - ("extended_stats", os_agg) - if os_agg in extended_stats_os_aggs - else os_agg + ( + ("extended_stats", os_agg) + if os_agg in extended_stats_os_aggs + else os_agg + ) for os_agg in os_aggs ] diff --git a/tests/dataframe/test_iterrows_itertuples_pytest.py b/tests/dataframe/test_iterrows_itertuples_pytest.py index d8cd57880..29c44d85c 100644 --- a/tests/dataframe/test_iterrows_itertuples_pytest.py +++ b/tests/dataframe/test_iterrows_itertuples_pytest.py @@ -61,9 +61,11 @@ def assert_tuples_almost_equal(left, right): # Shim which uses pytest.approx() for floating point values inside tuples. assert len(left) == len(right) assert all( - (lt == rt) # Not floats? Use == - if not isinstance(lt, float) and not isinstance(rt, float) - else (lt == pytest.approx(rt)) # If both are floats use pytest.approx() + ( + (lt == rt) # Not floats? Use == + if not isinstance(lt, float) and not isinstance(rt, float) + else (lt == pytest.approx(rt)) + ) # If both are floats use pytest.approx() for lt, rt in zip(left, right) ) diff --git a/utils/model_uploader/update_models_upload_history_md.py b/utils/model_uploader/update_models_upload_history_md.py index c625309a1..229ccceda 100644 --- a/utils/model_uploader/update_models_upload_history_md.py +++ b/utils/model_uploader/update_models_upload_history_md.py @@ -76,9 +76,9 @@ def create_model_json_obj( "Model ID": model_id, "Model Version": model_version, "Model Format": model_format, - "Embedding Dimension": str(embedding_dimension) - if embedding_dimension is not None - else "N/A", + "Embedding Dimension": ( + str(embedding_dimension) if embedding_dimension is not None else "N/A" + ), "Pooling Mode": pooling_mode if pooling_mode is not None else "N/A", "Workflow Run ID": workflow_id if workflow_id is not None else "-", }