From 630c81fb5da4b627aff62c3ee2fe34f4c226576b Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Tue, 21 May 2024 11:39:35 +0200 Subject: [PATCH 1/6] Fix missing method str.removeprefix in Python 3.8 --- eland/ml/pytorch/transformers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eland/ml/pytorch/transformers.py b/eland/ml/pytorch/transformers.py index bad24d87..e6d5df31 100644 --- a/eland/ml/pytorch/transformers.py +++ b/eland/ml/pytorch/transformers.py @@ -1059,5 +1059,10 @@ def elasticsearch_model_id(model_id: str) -> str: id = re.sub(r"[\s\\/]", "__", model_id).lower()[-64:] if id.startswith("__"): - id = id.removeprefix("__") + # This check is only needed as long as Eland supports Python 3.8 + # str.removeprefix was introduced in Python 3.9 + if sys.version_info > (3, 9, 0): + id = id.removeprefix("__") + else: + id = id[2:] return id From b39a790f03c5aad0d36dc0d0e15c21d4aa579684 Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Tue, 21 May 2024 11:46:31 +0200 Subject: [PATCH 2/6] Update transformers.py --- eland/ml/pytorch/transformers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eland/ml/pytorch/transformers.py b/eland/ml/pytorch/transformers.py index e6d5df31..6c6ace45 100644 --- a/eland/ml/pytorch/transformers.py +++ b/eland/ml/pytorch/transformers.py @@ -1061,7 +1061,7 @@ def elasticsearch_model_id(model_id: str) -> str: if id.startswith("__"): # This check is only needed as long as Eland supports Python 3.8 # str.removeprefix was introduced in Python 3.9 - if sys.version_info > (3, 9, 0): + if sys.version_info >= (3, 9, 0): id = id.removeprefix("__") else: id = id[2:] From c184454344ad8c63447ba2b460b4fccb948436b5 Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Tue, 21 May 2024 11:47:14 +0200 Subject: [PATCH 3/6] Update transformers.py --- eland/ml/pytorch/transformers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/eland/ml/pytorch/transformers.py b/eland/ml/pytorch/transformers.py index 6c6ace45..6363f888 100644 --- a/eland/ml/pytorch/transformers.py +++ b/eland/ml/pytorch/transformers.py @@ -24,6 +24,7 @@ import os.path import random import re +import sys from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Set, Tuple, Union From 3648486d301d110ede731fb4e00e639e326c011d Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Tue, 21 May 2024 22:50:14 +0200 Subject: [PATCH 4/6] Apply pull request feedback --- eland/ml/pytorch/transformers.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/eland/ml/pytorch/transformers.py b/eland/ml/pytorch/transformers.py index 6363f888..80ed556f 100644 --- a/eland/ml/pytorch/transformers.py +++ b/eland/ml/pytorch/transformers.py @@ -1061,9 +1061,7 @@ def elasticsearch_model_id(model_id: str) -> str: id = re.sub(r"[\s\\/]", "__", model_id).lower()[-64:] if id.startswith("__"): # This check is only needed as long as Eland supports Python 3.8 - # str.removeprefix was introduced in Python 3.9 - if sys.version_info >= (3, 9, 0): - id = id.removeprefix("__") - else: - id = id[2:] + # str.removeprefix was introduced in Python 3.9 and can be used + # once 3.8 support is dropped + id = id[2:] return id From e0ef34bd4dee2e941d2cb838fbc202c322c049ff Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Wed, 22 May 2024 12:34:18 +0000 Subject: [PATCH 5/6] Lint --- eland/ml/pytorch/transformers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eland/ml/pytorch/transformers.py b/eland/ml/pytorch/transformers.py index 80ed556f..e8cce6a2 100644 --- a/eland/ml/pytorch/transformers.py +++ b/eland/ml/pytorch/transformers.py @@ -1061,7 +1061,7 @@ def elasticsearch_model_id(model_id: str) -> str: id = re.sub(r"[\s\\/]", "__", model_id).lower()[-64:] if id.startswith("__"): # This check is only needed as long as Eland supports Python 3.8 - # str.removeprefix was introduced in Python 3.9 and can be used + # str.removeprefix was introduced in Python 3.9 and can be used # once 3.8 support is dropped id = id[2:] return id From 984e0f65387f722b59e5e53631c08e97a7c5afa3 Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Thu, 23 May 2024 15:45:31 +0200 Subject: [PATCH 6/6] Remove unused import --- eland/ml/pytorch/transformers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/eland/ml/pytorch/transformers.py b/eland/ml/pytorch/transformers.py index e8cce6a2..770e4f79 100644 --- a/eland/ml/pytorch/transformers.py +++ b/eland/ml/pytorch/transformers.py @@ -24,7 +24,6 @@ import os.path import random import re -import sys from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Set, Tuple, Union