From 8989231d3061936378aaeb20bab54a74a9c6b25f Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:53:56 -0500 Subject: [PATCH 1/2] Cleaned up typed array --- libs/labelbox/pyproject.toml | 4 +-- .../labelbox/data/annotation_types/types.py | 28 ++----------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/libs/labelbox/pyproject.toml b/libs/labelbox/pyproject.toml index 8a987492f..3b1a85668 100644 --- a/libs/labelbox/pyproject.toml +++ b/libs/labelbox/pyproject.toml @@ -47,7 +47,7 @@ Changelog = "https://github.com/Labelbox/labelbox-python/blob/develop/libs/label data = [ "shapely>=2.0.3", # numpy v2 breaks package since it only supports python >3.9 - "numpy>=1.24.4, <2.0.0", + "numpy>=1.25.0", "pillow>=10.2.0", "typeguard>=4.1.5", "imagesize>=1.4.1", @@ -95,7 +95,7 @@ integration = { cmd = "pytest tests/integration" } data = { cmd = "pytest tests/data" } rye-lint = "rye lint" rye-fmt-check = "rye fmt --check" -MYPYPATH="../lbox-clients/src/" +MYPYPATH = "../lbox-clients/src/" mypy-lint = "mypy src --pretty --show-error-codes --non-interactive --install-types" lint = { chain = ["rye-fmt-check", "mypy-lint", "rye-lint"] } test = { chain = ["lint", "unit", "integration"] } diff --git a/libs/labelbox/src/labelbox/data/annotation_types/types.py b/libs/labelbox/src/labelbox/data/annotation_types/types.py index f9b6ba492..4a9198fea 100644 --- a/libs/labelbox/src/labelbox/data/annotation_types/types.py +++ b/libs/labelbox/src/labelbox/data/annotation_types/types.py @@ -1,16 +1,12 @@ -import sys -from typing import Annotated, Any, Generic, TypeVar - +from typing import Generic, TypeVar import numpy as np -from packaging import version -from pydantic import ConfigDict, Field, StringConstraints from pydantic_core import core_schema DType = TypeVar("DType") DShape = TypeVar("DShape") -class _TypedArray(np.ndarray, Generic[DType, DShape]): +class TypedArray(np.ndarray, Generic[DType, DShape]): @classmethod def __get_pydantic_core_schema__( cls, _source_type: type, _model: type @@ -22,23 +18,3 @@ def validate(cls, val): if not isinstance(val, np.ndarray): raise TypeError(f"Expected numpy array. Found {type(val)}") return val - - -if version.parse(np.__version__) >= version.parse("1.25.0"): - from typing import GenericAlias - - TypedArray = GenericAlias(_TypedArray, (Any, DType)) -elif version.parse(np.__version__) >= version.parse("1.23.0"): - from numpy._typing import _GenericAlias - - TypedArray = _GenericAlias(_TypedArray, (Any, DType)) -elif ( - version.parse("1.22.0") - <= version.parse(np.__version__) - < version.parse("1.23.0") -): - from numpy.typing import _GenericAlias - - TypedArray = _GenericAlias(_TypedArray, (Any, DType)) -else: - TypedArray = _TypedArray[Any, DType] From 323f336d6af7958f02ac3b90b4d711727c0936af Mon Sep 17 00:00:00 2001 From: Gabe <33893811+Gabefire@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:55:04 -0500 Subject: [PATCH 2/2] remove comment --- libs/labelbox/pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/labelbox/pyproject.toml b/libs/labelbox/pyproject.toml index 3b1a85668..fa64c74f6 100644 --- a/libs/labelbox/pyproject.toml +++ b/libs/labelbox/pyproject.toml @@ -46,7 +46,6 @@ Changelog = "https://github.com/Labelbox/labelbox-python/blob/develop/libs/label [project.optional-dependencies] data = [ "shapely>=2.0.3", - # numpy v2 breaks package since it only supports python >3.9 "numpy>=1.25.0", "pillow>=10.2.0", "typeguard>=4.1.5",