Skip to content

Conversation

agaraman0
Copy link
Contributor

@agaraman0 agaraman0 commented May 24, 2023

fixes issue #1545

from docarray import BaseDoc, DocList, DocVec
from docarray.documents import ImageDoc


class Doc(BaseDoc):
    docs: DocList[ImageDoc]

d = Doc(docs=DocVec[ImageDoc]([ImageDoc()]))
# below gives <DocList[ImageDoc] (length=1)>
print(d.docs)


class OtherDoc(BaseDoc):
    docs: DocVec[ImageDoc]

d = Doc(docs=DocList[ImageDoc]([ImageDoc()]))
# below gives <DocVec[ImageDoc] (length=1)>
print(d.docs)

Signed-off-by: agaraman0 <agaraman0@gmail.com>
@agaraman0 agaraman0 marked this pull request as ready for review May 24, 2023 10:02
@JoanFM
Copy link
Member

JoanFM commented May 31, 2023

Hello @agaraman0 , can u please handle the tests and mypy errors?

Comment on lines 272 to 273
elif isinstance(value, DocVec):
return value.to_doc_list()
Copy link
Member

Choose a reason for hiding this comment

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

here we need to test if the documen_type of the value and self are compatible.

If they are you can silence mypy by return cast(T, )

Comment on lines 272 to 273
elif isinstance(value, DocVec):
return value.to_doc_list()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
elif isinstance(value, DocVec):
return value.to_doc_list()
elif isinstance(value, DocVec):
if issubclass(value.doc_type, self.doc_type) or value.doc_type == cls.doc_type:
return cast(T, value.to_doc_list()
else:
raise ValueError(f'DocList[value.doc_type] is not compatible with {cls}')

Copy link
Member

Choose a reason for hiding this comment

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

smth like this

agaraman0 added 3 commits June 4, 2023 10:01
Signed-off-by: agaraman0 <agaraman0@gmail.com>
Signed-off-by: agaraman0 <agaraman0@gmail.com>
Signed-off-by: agaraman0 <agaraman0@gmail.com>
Signed-off-by: agaraman0 <agaraman0@gmail.com>
@samsja samsja merged commit 693f877 into docarray:main Jun 7, 2023
@JoanFM JoanFM linked an issue Jun 14, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation bug: DocList and DocVec are not coerced to each other
3 participants