Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
e26c6c5
feat: init commit on adding v2 support
samsja Jun 15, 2023
30a8c17
feat: make some progress
samsja Jun 15, 2023
ee347b0
fix: fix test update
samsja Jun 15, 2023
64216c7
fix: fix refactoring validation
samsja Jun 15, 2023
8989d82
fix: fix ndarray and doclist
samsja Jun 15, 2023
e2082d9
fix: move to var
samsja Jun 15, 2023
c20f49b
fix: fix some stuff
samsja Jun 16, 2023
b55005f
fix: fix some stuff on v1
samsja Jun 16, 2023
1d7097c
feat: pass half of the test
samsja Jun 16, 2023
addf361
fix: add schema to doc vec
samsja Jun 16, 2023
168163b
feat: fix anyurl
samsja Jun 16, 2023
a7d30ed
fix: remove useles try catch
samsja Jun 19, 2023
979edc7
refactor: use _docarray_fields everywhere
samsja Jun 19, 2023
0d1e194
fix: fix is required
samsja Jun 19, 2023
f370888
fix: fix validation of any url
samsja Jun 19, 2023
dd0f96a
fix: make dict and json pydantic v1 only for now
samsja Jun 22, 2023
aaf47d0
fix: use string as id in tests
samsja Jun 22, 2023
46d15d2
fix: doc view
samsja Jun 22, 2023
a06b778
fix: test traverse test
samsja Jun 22, 2023
9f5098d
fix: fix any url
samsja Jun 22, 2023
6f69a64
fix: type_
samsja Jun 22, 2023
7856e11
fix: outer type pb
samsja Jun 22, 2023
140158c
fix: .type_
samsja Jun 22, 2023
2d3bdb9
fix: add pydantic extra to from view
samsja Jun 22, 2023
6059add
fix: fix smth
samsja Jun 22, 2023
7bf8874
refactor: rename get fild type
samsja Jun 22, 2023
083415e
refactor: fix field type
samsja Jun 22, 2023
3de330d
chore: bump fastapi
samsja Jul 20, 2023
fb91500
chore: fix test audio tensor
samsja Jul 20, 2023
ae2855c
chore: fix field set warning
samsja Jul 20, 2023
afb15b5
chore: fix shallow copy
samsja Jul 20, 2023
8f4814f
fix: fix smth
samsja Jul 20, 2023
aaaf17e
fix: fix smth
samsja Jul 20, 2023
e6f0748
fix: fix recursion schem display
samsja Jul 20, 2023
9a4a5b1
fix: fix rsmth
samsja Jul 20, 2023
98a4507
fix: fix id
samsja Jul 20, 2023
2212b48
fix: fix json
samsja Jul 20, 2023
2cc068a
fix: fix tests
samsja Jul 20, 2023
3909184
fix: fix msht
samsja Jul 21, 2023
0e23c67
fix: fix dump
samsja Aug 3, 2023
e46764d
feat: add tests
samsja Aug 3, 2023
71978a4
fix: fix tests
samsja Aug 3, 2023
ef4f916
fix: fix tests
samsja Aug 3, 2023
8acda4e
fix: fix proto
samsja Aug 3, 2023
c75f02d
fix: fix proto
samsja Aug 3, 2023
41be289
fix: fix dict any doc
samsja Aug 3, 2023
97ba6a2
fix: fix smth
samsja Aug 4, 2023
0bddc8b
fix: fix some other tests
samsja Aug 7, 2023
3d96901
fix: skip failing v2 tests for later
samsja Aug 7, 2023
4b4031c
fix: pass video tensor
samsja Aug 7, 2023
0267c43
feat: wip add json support for tensor
samsja Aug 9, 2023
076f4eb
feat: add orjsons support for tensor
samsja Aug 9, 2023
eac18fa
fix: merege in progress
samsja Aug 22, 2023
efb2109
fix: image url proto
samsja Aug 23, 2023
72eae9f
fix: fix some tests
samsja Aug 23, 2023
e1b5868
fix: fix some tests
samsja Aug 23, 2023
88be3be
fix: fix some tests
samsja Aug 23, 2023
efcc877
fix: fix some tests regarding anyurl
samsja Aug 23, 2023
94f7e13
fix: fix any url problem
samsja Aug 23, 2023
448fa32
fix: add missing method
samsja Aug 23, 2023
47b86a5
fix: fix json
samsja Aug 25, 2023
193ec11
fix: fix some tests
samsja Aug 28, 2023
d952729
fix: fix some tests
samsja Aug 28, 2023
8dba04e
fix: fix some tests
samsja Aug 28, 2023
6e1241c
fix: fix some tests
samsja Aug 28, 2023
db0768d
fix: fix some tests
samsja Aug 28, 2023
d32b3ed
fix: fix tests
samsja Aug 28, 2023
bc24031
chore: update ci#
samsja Aug 29, 2023
c57067b
chore: add gitnignore
samsja Aug 29, 2023
386b25f
fix: fix code to be compatible with python 3.8
samsja Aug 29, 2023
4e01dc0
chore: install v2 in c
samsja Aug 29, 2023
71f5645
Merge branch 'main' into feat-full-pydantic-v2-support
samsja Aug 29, 2023
8db8da3
chore: install v2 in c
samsja Aug 29, 2023
c639703
fix: fix some tests
samsja Aug 29, 2023
f25ff1a
chore: fix pydantic v2 install
samsja Aug 30, 2023
57097fe
fix: fix some integration tests
samsja Aug 30, 2023
568e7d3
fix: fix mesh 3d val
samsja Aug 30, 2023
99f675a
fix: fix spcript
samsja Aug 30, 2023
d1142e3
chore: fix smth
samsja Aug 30, 2023
6bcf372
chore: fix smth
samsja Aug 30, 2023
ed231a0
fix: fix import
samsja Aug 31, 2023
e7364a8
fix: fix audio test v2
samsja Aug 31, 2023
62f48b6
fix: fix some tests integrations
samsja Aug 31, 2023
5042293
fix: fix some integrations tests
samsja Aug 31, 2023
3d0dbfe
fix: fix some mesh tests
samsja Aug 31, 2023
24c4bb1
fix: fix point cloud
samsja Aug 31, 2023
e105146
fix: fix some tests
samsja Aug 31, 2023
d86d196
chore: add marker
samsja Aug 31, 2023
de03e81
fix: fix some tests
samsja Aug 31, 2023
3383a52
fix: pass tests for now
samsja Aug 31, 2023
9ecf204
fix: issue with id json schema
samsja Sep 1, 2023
9054727
chore: do pydantic v2 test everywhere
samsja Sep 1, 2023
c910887
fix: fix poetry lock
samsja Sep 5, 2023
6a3dd8a
fix: update qdrant
samsja Sep 5, 2023
580832e
fix: wip fix pydantic v2 index tests
samsja Sep 5, 2023
ad46ab7
fix: fix pydantic v2 index test
samsja Sep 5, 2023
4ff7eae
fix: fix redis tests
samsja Sep 5, 2023
38a6982
fix: fix el v7 tests
samsja Sep 5, 2023
cd56d8c
fix: fix el v8 tests
samsja Sep 5, 2023
610a3aa
Merge branch 'main' into feat-full-pydantic-v2-support
samsja Sep 5, 2023
9aa12e1
fix: last tests
samsja Sep 5, 2023
8f2ee87
fix: tensorflow pydantic v2 tests
samsja Sep 6, 2023
cf5654b
fix: fix jax with pydantic v
samsja Sep 6, 2023
4613e20
fix: silence on last test
samsja Sep 6, 2023
4134da5
fix: silence on last test
samsja Sep 6, 2023
c259b09
fix: docstring validate
samsja Sep 7, 2023
02b2b61
fix: docstring validate
samsja Sep 7, 2023
cbf7a87
fix: put back cast
samsja Sep 7, 2023
5e2378e
feat: apply johannes suggestion
samsja Sep 7, 2023
19e444b
feat: add comment
samsja Sep 7, 2023
a16018a
feat: add comment
samsja Sep 7, 2023
863e0b8
fix: skip docstrng tet for pydantic v2 for now
samsja Sep 7, 2023
d7a7a49
fix: skip docstrng tet for pydantic v2 for now
samsja Sep 8, 2023
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
Prev Previous commit
Next Next commit
fix: fix some stuff
Signed-off-by: samsja <[email protected]>
  • Loading branch information
samsja committed Jun 16, 2023
commit c20f49baf01ef5649471145a8841a1e1307a6b07
27 changes: 3 additions & 24 deletions docarray/typing/bytes/audio_bytes.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
import io
from typing import TYPE_CHECKING, Any, Tuple, Type, TypeVar
from typing import Tuple, TypeVar

import numpy as np
from pydantic import parse_obj_as

from docarray.typing.abstract_type import AbstractType
from docarray.typing.bytes.base_bytes import BaseBytes
from docarray.typing.proto_register import _register_proto
from docarray.typing.tensor.audio import AudioNdArray
from docarray.utils._internal.misc import import_library
from docarray.utils._internal.pydantic import bytes_validator

if TYPE_CHECKING:
from docarray.proto import NodeProto

T = TypeVar('T', bound='AudioBytes')


@_register_proto(proto_type_name='audio_bytes')
class AudioBytes(bytes, AbstractType):
class AudioBytes(BaseBytes):
"""
Bytes that store an audio and that can be load into an Audio tensor
"""

@classmethod
def _docarray_validate(
cls: Type[T],
value: Any,
) -> T:
value = bytes_validator(value)
return cls(value)

@classmethod
def from_protobuf(cls: Type[T], pb_msg: T) -> T:
return parse_obj_as(cls, pb_msg)

def _to_node_protobuf(self: T) -> 'NodeProto':
from docarray.proto import NodeProto

return NodeProto(blob=self, type=self._proto_type_name)

def load(self) -> Tuple[AudioNdArray, int]:
"""
Load the Audio from the [`AudioBytes`][docarray.typing.AudioBytes] into an
Expand Down
53 changes: 53 additions & 0 deletions docarray/typing/bytes/base_bytes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Type, TypeVar

from pydantic import parse_obj_as

from docarray.typing.abstract_type import AbstractType
from docarray.utils._internal.pydantic import bytes_validator, is_pydantic_v2

if is_pydantic_v2:
from pydantic_core import core_schema

if TYPE_CHECKING:
from docarray.proto import NodeProto

if is_pydantic_v2:
from pydantic import GetCoreSchemaHandler

T = TypeVar('T', bound='BaseBytes')


class BaseBytes(bytes, AbstractType):
"""
Bytes type for docarray
"""

@classmethod
def _docarray_validate(
cls: Type[T],
value: Any,
) -> T:
value = bytes_validator(value)
return cls(value)

@classmethod
def from_protobuf(cls: Type[T], pb_msg: T) -> T:
return parse_obj_as(cls, pb_msg)

def _to_node_protobuf(self: T) -> 'NodeProto':
from docarray.proto import NodeProto

return NodeProto(blob=self, type=self._proto_type_name)

if is_pydantic_v2:

@classmethod
@abstractmethod
def __get_pydantic_core_schema__(
cls, _source_type: Any, _handler: 'GetCoreSchemaHandler'
) -> 'core_schema.CoreSchema':
return core_schema.general_after_validator_function(
cls.validate,
core_schema.bytes_schema(),
)
25 changes: 3 additions & 22 deletions docarray/typing/bytes/image_bytes.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,27 @@
from io import BytesIO
from typing import TYPE_CHECKING, Any, Optional, Tuple, Type, TypeVar
from typing import TYPE_CHECKING, Optional, Tuple, TypeVar

import numpy as np
from pydantic import parse_obj_as

from docarray.typing.abstract_type import AbstractType
from docarray.typing.bytes.base_bytes import BaseBytes
from docarray.typing.proto_register import _register_proto
from docarray.typing.tensor.image.image_ndarray import ImageNdArray
from docarray.utils._internal.misc import import_library
from docarray.utils._internal.pydantic import bytes_validator

if TYPE_CHECKING:
from PIL import Image as PILImage

from docarray.proto import NodeProto

T = TypeVar('T', bound='ImageBytes')


@_register_proto(proto_type_name='image_bytes')
class ImageBytes(bytes, AbstractType):
class ImageBytes(BaseBytes):
"""
Bytes that store an image and that can be load into an image tensor
"""

@classmethod
def _docarray_validate(
cls: Type[T],
value: Any,
) -> T:
value = bytes_validator(value)
return cls(value)

@classmethod
def from_protobuf(cls: Type[T], pb_msg: T) -> T:
return parse_obj_as(cls, pb_msg)

def _to_node_protobuf(self: T) -> 'NodeProto':
from docarray.proto import NodeProto

return NodeProto(blob=self, type=self._proto_type_name)

def load_pil(
self,
) -> 'PILImage.Image':
Expand Down
27 changes: 3 additions & 24 deletions docarray/typing/bytes/video_bytes.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from io import BytesIO
from typing import TYPE_CHECKING, Any, List, NamedTuple, Type, TypeVar
from typing import TYPE_CHECKING, List, NamedTuple, TypeVar

import numpy as np
from pydantic import parse_obj_as

from docarray.typing.abstract_type import AbstractType
from docarray.typing.bytes.base_bytes import BaseBytes
from docarray.typing.proto_register import _register_proto
from docarray.typing.tensor import AudioNdArray, NdArray, VideoNdArray
from docarray.utils._internal.misc import import_library
from docarray.utils._internal.pydantic import bytes_validator

if TYPE_CHECKING:
from docarray.proto import NodeProto

T = TypeVar('T', bound='VideoBytes')

Expand All @@ -23,28 +19,11 @@ class VideoLoadResult(NamedTuple):


@_register_proto(proto_type_name='video_bytes')
class VideoBytes(bytes, AbstractType):
class VideoBytes(BaseBytes):
"""
Bytes that store a video and that can be load into a video tensor
"""

@classmethod
def _docarray_validate(
cls: Type[T],
value: Any,
) -> T:
value = bytes_validator(value)
return cls(value)

@classmethod
def from_protobuf(cls: Type[T], pb_msg: T) -> T:
return parse_obj_as(cls, pb_msg)

def _to_node_protobuf(self: T) -> 'NodeProto':
from docarray.proto import NodeProto

return NodeProto(blob=self, type=self._proto_type_name)

def load(self, **kwargs) -> VideoLoadResult:
"""
Load the video from the bytes into a VideoLoadResult object consisting of:
Expand Down
23 changes: 21 additions & 2 deletions docarray/typing/url/any_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
from pydantic import AnyUrl as BaseAnyUrl
from pydantic import errors, parse_obj_as
from pydantic_core import core_schema

from docarray.typing.abstract_type import AbstractType
from docarray.typing.proto_register import _register_proto
Expand All @@ -16,6 +17,8 @@
if not is_pydantic_v2:
from pydantic import BaseConfig
from pydantic.fields import ModelField
else:
from pydantic import GetCoreSchemaHandler

from pydantic.networks import Parts

Expand All @@ -27,9 +30,25 @@
if is_pydantic_v2:

@_register_proto(proto_type_name='any_url')
class AnyUrl:
class AnyUrl(AbstractType):
def __init__(self, *args, **kwargs):
raise NotImplementedError('AnyUrl is not supported in pydantic v2')
raise NotImplementedError('AnyUrl is not supported in pydantic v2 for now')

@classmethod
def _docarray_validate(
cls: Type[T],
value: Any,
):
raise NotImplementedError('AnyUrl is not supported in pydantic v2 for now')

def __get_pydantic_core_schema__(
cls, source: type[Any], handler: Optional['GetCoreSchemaHandler'] = None
) -> core_schema.CoreSchema:

return core_schema.general_after_validator_function(
cls._docarray_validate,
core_schema.str_schema(),
)

else:

Expand Down
4 changes: 2 additions & 2 deletions docarray/utils/_internal/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
from pydantic.validators import bytes_validator

else:
from pydantic.v1.validators import bytes_validator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I understanding correctly that we are falling back to the bytes validator of v1 even if pydantic v2 is used? What is the reason behind this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


def bytes_validator(*args, **kwargs):
raise NotImplementedError('bytes_validator is not implemented in pydantic v2')
__all__ = ['is_pydantic_v2', 'bytes_validator']