Skip to content

fix: better generic support in document array stack #1147

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 12 commits into from
Feb 20, 2023
Prev Previous commit
Next Next commit
refactor: create io mixin for docuemnt array
Signed-off-by: samsja <sami.jaghouar@hotmail.fr>
  • Loading branch information
samsja committed Feb 17, 2023
commit 5e324cf5156b28f616f9d8234823d0b0eacaa417
8 changes: 8 additions & 0 deletions docarray/array/array/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from pydantic.fields import ModelField

from docarray.array.stacked.array_stacked import DocumentArrayStacked
from docarray.proto import DocumentArrayProto
from docarray.typing import TorchTensor
from docarray.typing.tensor.abstract_tensor import AbstractTensor

Expand Down Expand Up @@ -433,3 +434,10 @@ def traverse_flat(
flattened = AnyDocumentArray._flatten_one_level(nodes)

return flattened

@classmethod
def from_protobuf(cls: Type[T], pb_msg: 'DocumentArrayProto') -> T:
"""create a Document from a protobuf message
:param pb_msg: The protobuf message from where to construct the DocumentArray
"""
return super().from_protobuf(pb_msg)
15 changes: 14 additions & 1 deletion docarray/array/array/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import os
import pathlib
import pickle
from abc import abstractmethod
from contextlib import nullcontext
from typing import (
TYPE_CHECKING,
BinaryIO,
ContextManager,
Generator,
Iterable,
Optional,
Sized,
Tuple,
Type,
TypeVar,
Expand Down Expand Up @@ -78,7 +81,17 @@ def __getitem__(self, item: slice):
return self.content[item]


class IOMixinArray:
class IOMixinArray(Iterable[BaseDocument], Sized):

document_type: Type[BaseDocument]

@abstractmethod
def __init__(
self,
docs: Optional[Iterable[BaseDocument]] = None,
):
...

@classmethod
def from_protobuf(cls: Type[T], pb_msg: 'DocumentArrayProto') -> T:
"""create a Document from a protobuf message
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy