Skip to content

feat: allow da bulk access to return da for document#803

Merged
JohannesMessner merged 4 commits into
feat-rewrite-v2from
feat-v2-allow-da-document-bulk-acces
Nov 17, 2022
Merged

feat: allow da bulk access to return da for document#803
JohannesMessner merged 4 commits into
feat-rewrite-v2from
feat-v2-allow-da-document-bulk-acces

Conversation

@samsja

@samsja samsja commented Nov 16, 2022

Copy link
Copy Markdown
Member

Context

since #790 we can already do

from docarray import DocumentArray, Document

class Mmdoc(BaseDocument):
    text: str

da = DocumentArray[Mmdoc](
    (Mmdoc(text=f'hello') for _ in range(10))
)

assert da.text == 10*['hello']

never the less it always return a list of item for the field, even if the field is suppose to contain Document. In this case this should return a DocumentArray instead of a List of Document

What this pr do

When the nested field is a Document it returns a DocumentArray instead of a List of Document

from docarray import Text

class Mmdoc(BaseDocument):
    text: Text

da = DocumentArray[Mmdoc](
    (Mmdoc(text=Text(text='hello')) for _ in range(10))
)

assert da.text == DocumentArray[Text](10*[Text(text='hello'))])

@JohannesMessner

Copy link
Copy Markdown
Member

What happens in the following case?

from docarray import Text

class Mmdoc(BaseDocument):
    text: DocumentArray[Text]

da = DocumentArray[Mmdoc](
    (Mmdoc(text=DocumentArray([Text(text='hello') for _ in range(5)]) for _ in range(10)))
)

assert da.text == ???

From reading the code it looks like it would return a list of DocumentArrays.

Is this already supported? If yes, can we have a test for it?

@samsja

samsja commented Nov 17, 2022

Copy link
Copy Markdown
Member Author

Yes this will return a list of document array. Is this the behavior we want to have ? I believe yes

@samsja samsja force-pushed the feat-v2-allow-da-document-bulk-acces branch from 9ece60c to 808acf9 Compare November 17, 2022 13:50
Signed-off-by: Sami Jaghouar <sami.jaghouar@hotmail.fr>
Signed-off-by: Sami Jaghouar <sami.jaghouar@hotmail.fr>
Signed-off-by: Sami Jaghouar <sami.jaghouar@hotmail.fr>
Signed-off-by: Sami Jaghouar <sami.jaghouar@hotmail.fr>
@samsja samsja force-pushed the feat-v2-allow-da-document-bulk-acces branch from 808acf9 to efa4513 Compare November 17, 2022 14:16
@JohannesMessner JohannesMessner merged commit 13c83b3 into feat-rewrite-v2 Nov 17, 2022
@JohannesMessner JohannesMessner deleted the feat-v2-allow-da-document-bulk-acces branch November 17, 2022 14:58
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.

2 participants