diff --git a/python/pyproject.toml b/python/pyproject.toml index cd09df7b..861cfdc5 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -10,7 +10,7 @@ dependencies = [ "tqdm>=4.27.0", "pydantic>=1.10", "attrs>=21.3.0", - "semver", + "packaging", "cachetools", "overrides>=0.7", ] diff --git a/python/python/lancedb/embeddings/bedrock.py b/python/python/lancedb/embeddings/bedrock.py index dab926a9..767faa65 100644 --- a/python/python/lancedb/embeddings/bedrock.py +++ b/python/python/lancedb/embeddings/bedrock.py @@ -74,7 +74,7 @@ class BedRockText(TextEmbeddingFunction): profile_name: Union[str, None] = None role_session_name: str = "lancedb-embeddings" - if PYDANTIC_VERSION < (2, 0): # Pydantic 1.x compat + if PYDANTIC_VERSION.major < 2: # Pydantic 1.x compat class Config: keep_untouched = (cached_property,) diff --git a/python/python/lancedb/embeddings/gemini_text.py b/python/python/lancedb/embeddings/gemini_text.py index e3a9b96d..55afc5e0 100644 --- a/python/python/lancedb/embeddings/gemini_text.py +++ b/python/python/lancedb/embeddings/gemini_text.py @@ -90,7 +90,7 @@ class GeminiText(TextEmbeddingFunction): query_task_type: str = "retrieval_query" source_task_type: str = "retrieval_document" - if PYDANTIC_VERSION < (2, 0): # Pydantic 1.x compat + if PYDANTIC_VERSION.major < 2: # Pydantic 1.x compat class Config: keep_untouched = (cached_property,) diff --git a/python/python/lancedb/embeddings/imagebind.py b/python/python/lancedb/embeddings/imagebind.py index 634b1487..d66e44fb 100644 --- a/python/python/lancedb/embeddings/imagebind.py +++ b/python/python/lancedb/embeddings/imagebind.py @@ -40,7 +40,7 @@ class ImageBindEmbeddings(EmbeddingFunction): device: str = "cpu" normalize: bool = False - if PYDANTIC_VERSION < (2, 0): # Pydantic 1.x compat + if PYDANTIC_VERSION.major < 2: # Pydantic 1.x compat class Config: keep_untouched = (cached_property,) diff --git a/python/python/lancedb/embeddings/transformers.py b/python/python/lancedb/embeddings/transformers.py index 02696c4f..a20f27ff 100644 --- a/python/python/lancedb/embeddings/transformers.py +++ b/python/python/lancedb/embeddings/transformers.py @@ -54,7 +54,7 @@ class TransformersEmbeddingFunction(EmbeddingFunction): self._tokenizer = transformers.AutoTokenizer.from_pretrained(self.name) self._model = transformers.AutoModel.from_pretrained(self.name) - if PYDANTIC_VERSION < (2, 0): # Pydantic 1.x compat + if PYDANTIC_VERSION.major < 2: # Pydantic 1.x compat class Config: keep_untouched = (cached_property,) diff --git a/python/python/lancedb/pydantic.py b/python/python/lancedb/pydantic.py index f4347f0d..9aaf2857 100644 --- a/python/python/lancedb/pydantic.py +++ b/python/python/lancedb/pydantic.py @@ -35,13 +35,13 @@ from typing import ( import numpy as np import pyarrow as pa import pydantic -import semver +from packaging.version import Version -PYDANTIC_VERSION = semver.parse_version_info(pydantic.__version__) +PYDANTIC_VERSION = Version(pydantic.__version__) try: from pydantic_core import CoreSchema, core_schema except ImportError: - if PYDANTIC_VERSION >= (2,): + if PYDANTIC_VERSION.major >= 2: raise if TYPE_CHECKING: @@ -144,7 +144,7 @@ def Vector( raise TypeError("A list of numbers or numpy.ndarray is needed") return cls(v) - if PYDANTIC_VERSION < (2, 0): + if PYDANTIC_VERSION.major < 2: @classmethod def __modify_schema__(cls, field_schema: Dict[str, Any]): diff --git a/python/python/lancedb/rerankers/cohere.py b/python/python/lancedb/rerankers/cohere.py index 373e76b8..4018d44c 100644 --- a/python/python/lancedb/rerankers/cohere.py +++ b/python/python/lancedb/rerankers/cohere.py @@ -1,5 +1,5 @@ import os -import semver +from packaging.version import Version from functools import cached_property from typing import Union @@ -44,9 +44,8 @@ class CohereReranker(Reranker): def _client(self): cohere = attempt_import_or_raise("cohere") # ensure version is at least 0.5.0 - if ( - hasattr(cohere, "__version__") - and semver.compare(cohere.__version__, "5.0.0") < 0 + if hasattr(cohere, "__version__") and Version(cohere.__version__) < Version( + "0.5.0" ): raise ValueError( f"cohere version must be at least 0.5.0, found {cohere.__version__}" diff --git a/python/python/tests/test_pydantic.py b/python/python/tests/test_pydantic.py index 8f9d335c..5b401334 100644 --- a/python/python/tests/test_pydantic.py +++ b/python/python/tests/test_pydantic.py @@ -178,7 +178,7 @@ def test_fixed_size_list_field(): li: List[int] data = TestModel(vec=list(range(16)), li=[1, 2, 3]) - if PYDANTIC_VERSION >= (2,): + if PYDANTIC_VERSION.major >= 2: assert json.loads(data.model_dump_json()) == { "vec": list(range(16)), "li": [1, 2, 3], @@ -197,7 +197,7 @@ def test_fixed_size_list_field(): ] ) - if PYDANTIC_VERSION >= (2,): + if PYDANTIC_VERSION.major >= 2: json_schema = TestModel.model_json_schema() else: json_schema = TestModel.schema()