Skip to content

[PLT-1580] Cleaned up typed array #1858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions libs/labelbox/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ 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.24.4, <2.0.0",
"numpy>=1.25.0",
"pillow>=10.2.0",
"typeguard>=4.1.5",
"imagesize>=1.4.1",
Expand Down Expand Up @@ -95,7 +94,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"] }
Expand Down
28 changes: 2 additions & 26 deletions libs/labelbox/src/labelbox/data/annotation_types/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Loading