-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathdocumentarray.py
More file actions
39 lines (28 loc) · 1.07 KB
/
Copy pathdocumentarray.py
File metadata and controls
39 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import Iterable, Type
from docarray.document import AnyDocument, BaseDocument
from docarray.document.abstract_document import AbstractDocument
from docarray.typing import BaseNode
from .abstract_array import AbstractDocumentArray
from .mixins import ProtoArrayMixin
class DocumentArray(
list,
ProtoArrayMixin,
AbstractDocumentArray,
BaseNode,
):
"""
a _GenericDocumentArray is a list-like container of Document of the same schema
:param docs: iterable of Document
"""
document_type: Type[BaseDocument] = AnyDocument
def __init__(self, docs: Iterable[AbstractDocument]):
super().__init__(doc_ for doc_ in docs)
def __class_getitem__(cls, item: Type[BaseDocument]):
if not issubclass(item, BaseDocument):
raise ValueError(
f'DocumentArray[item] item should be a Document not a {item} '
)
class _DocumenArrayTyped(DocumentArray):
document_type = item
_DocumenArrayTyped.__name__ = f'DocumentArray{item.__name__}'
return _DocumenArrayTyped