Skip to content

feat: add nested access for document array#956

Merged
JoanFM merged 26 commits intofeat-rewrite-v2from
feat-nested-access
Dec 23, 2022
Merged

feat: add nested access for document array#956
JoanFM merged 26 commits intofeat-rewrite-v2from
feat-nested-access

Conversation

@anna-charlotte
Copy link
Contributor

@anna-charlotte anna-charlotte commented Dec 19, 2022

Signed-off-by: anna-charlotte [email protected]

Nested access in V2 is possible by calling the nested attributes you want to access on a DocumentArray, e.g. da.image.title. This does not work for nested DocumentArrays though:

class Author(Document):
    name: str


class Book(Document):
    authors: Optional[DocumentArray[Author]]
    content: str


da = DocumentArray[Book](
    [
        Book(
            authors=DocumentArray[Author]([Author(name='Jenny'), Author(name='Ben')]),
            content=f'hello{i}'
        ) for i in range(10)
    ]
)

authors = da.authors.name  # does not work since da.authors is a list of DocumentArrays and does not have

# instead do this:
authors = da.traverse_flat(access_path='authors.name')  # returns List of strings, with len = 20

traverse_flat takes the access path and returns a list of those attributes, flattened on the first level.
da.traverse_flat(access_path='authors.name') therefore returns a list of 20 strings instead of list of ten lists of 2 names each.

  • add traverse_flat + test
  • check and update documentation, if required. See guide

anna-charlotte added 9 commits December 20, 2022 15:00
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte added 9 commits December 20, 2022 15:14
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte added 4 commits December 22, 2022 18:00
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte added 3 commits December 23, 2022 11:42
@anna-charlotte anna-charlotte marked this pull request as ready for review December 23, 2022 10:47
@github-actions
Copy link

📝 Docs are deployed on https://ft-feat-nested-access--jina-docs.netlify.app 🎉

@JoanFM
Copy link
Member

JoanFM commented Dec 23, 2022

In the v1, we decided to hide traverse flat behind the [@] accessors, are we expecting to expose this now?

@anna-charlotte
Copy link
Contributor Author

@Joan We haven't made the final decision for this yet. For now, we decided on exposing it, but want to reevaluate this when Sami and Johannes are back.

@JoanFM JoanFM merged commit 6e66c31 into feat-rewrite-v2 Dec 23, 2022
@JoanFM JoanFM deleted the feat-nested-access branch December 23, 2022 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate nested access from DocumentArray ("access paths")

2 participants