Skip to content

fix: adding an int() cast to avoid IndexError#394

Merged
alaeddine-13 merged 6 commits into
docarray:mainfrom
lhr0909:patch-1
Jun 13, 2022
Merged

fix: adding an int() cast to avoid IndexError#394
alaeddine-13 merged 6 commits into
docarray:mainfrom
lhr0909:patch-1

Conversation

@lhr0909

@lhr0909 lhr0909 commented Jun 9, 2022

Copy link
Copy Markdown
Contributor

Goals:

to resolve #393

  • ...
  • ...
  • check and update documentation, if required. See guide

@numb3r3 numb3r3 requested a review from alaeddine-13 June 9, 2022 04:28
@codecov

codecov Bot commented Jun 9, 2022

Copy link
Copy Markdown

Codecov Report

Merging #394 (c6fbf9a) into main (d559752) will increase coverage by 1.76%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #394      +/-   ##
==========================================
+ Coverage   84.77%   86.53%   +1.76%     
==========================================
  Files         134      134              
  Lines        6358     6388      +30     
==========================================
+ Hits         5390     5528     +138     
+ Misses        968      860     -108     
Flag Coverage Δ
docarray 86.53% <100.00%> (+1.76%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
docarray/__init__.py 75.00% <100.00%> (ø)
docarray/dataclasses/types.py 91.37% <100.00%> (ø)
docarray/document/mixins/multimodal.py 93.33% <100.00%> (ø)
docarray/array/storage/qdrant/backend.py 95.87% <0.00%> (-0.05%) ⬇️
docarray/array/storage/weaviate/backend.py 87.50% <0.00%> (ø)
docarray/array/storage/annlite/backend.py 95.71% <0.00%> (+0.12%) ⬆️
docarray/helper.py 81.73% <0.00%> (+0.33%) ⬆️
docarray/array/storage/memory/find.py 91.22% <0.00%> (+1.75%) ⬆️
docarray/array/storage/elastic/backend.py 94.59% <0.00%> (+2.07%) ⬆️
docarray/array/mixins/getattr.py 81.81% <0.00%> (+3.03%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae4d63b...c6fbf9a. Read the comment docs.

@alaeddine-13 alaeddine-13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you also add a test that shows the issue ?

Comment thread docarray/document/mixins/multimodal.py
Comment thread docarray/document/mixins/multimodal.py
Comment thread docarray/document/mixins/multimodal.py
@numb3r3

numb3r3 commented Jun 10, 2022

Copy link
Copy Markdown
Contributor

@lhr0909 I created a mvp example to reproduce your issue outside of Jina Flow:

from typing import TypeVar, List
from docarray import dataclass, field, Document, DocumentArray
from docarray.typing import Image, Text, JSON

TrialImages = TypeVar('TrialImages', bound=str)

def trial_images_setter(value: List[str]) -> Document:
    # TODO: this is still not a multi-modal document, but I think it is fine for now
    doc = Document(modality='trial_images')
    doc.chunks = [Document(uri=uri, modality='image') for uri in value]
    return doc

def trial_images_getter(doc: Document) -> List[str]:
    return [d.uri for d in doc.chunks]

@dataclass
class Lipstick:
    brand: Text
    color: Text
    nickname: Text
    meta: JSON
    product_image: Image
    # nested document for embeddings of skin and lip colors from all the trials
    trial_images: TrialImages = field(setter=trial_images_setter, getter=trial_images_getter, default_factory=[])


lip = Lipstick(brand='nike', color='blue', nickname='nicke', meta={}, product_image='tests/image-data/05978.jpg', trial_images=['http://a.b.c/o.jpeg'])

d = Document(lip)
da = DocumentArray([d])

trial_images = da['@.[trial_images]c']

# serializing
pb = da.to_protobuf()

# deserializing
nda = DocumentArray.from_protobuf(pb)
trial_images = nda['@.[trial_images]c']

Hope this can help you to add a unitest to cover this issue

Comment thread docarray/document/mixins/multimodal.py Outdated
'attribute_type'
]
position = self._metadata['multi_modal_schema'][attribute].get('position')
position = int(self._metadata['multi_modal_schema'][attribute].get('position'))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alaeddine-13 Yeah I tried this, and this breaks tests which don't generate position attribute. So that's why I cast to int inside the branch.

@lhr0909

lhr0909 commented Jun 13, 2022

Copy link
Copy Markdown
Contributor Author

@lhr0909 I created a mvp example to reproduce your issue outside of Jina Flow:

from typing import TypeVar, List
from docarray import dataclass, field, Document, DocumentArray
from docarray.typing import Image, Text, JSON

TrialImages = TypeVar('TrialImages', bound=str)

def trial_images_setter(value: List[str]) -> Document:
    # TODO: this is still not a multi-modal document, but I think it is fine for now
    doc = Document(modality='trial_images')
    doc.chunks = [Document(uri=uri, modality='image') for uri in value]
    return doc

def trial_images_getter(doc: Document) -> List[str]:
    return [d.uri for d in doc.chunks]

@dataclass
class Lipstick:
    brand: Text
    color: Text
    nickname: Text
    meta: JSON
    product_image: Image
    # nested document for embeddings of skin and lip colors from all the trials
    trial_images: TrialImages = field(setter=trial_images_setter, getter=trial_images_getter, default_factory=[])


lip = Lipstick(brand='nike', color='blue', nickname='nicke', meta={}, product_image='tests/image-data/05978.jpg', trial_images=['http://a.b.c/o.jpeg'])

d = Document(lip)
da = DocumentArray([d])

trial_images = da['@.[trial_images]c']

# serializing
pb = da.to_protobuf()

# deserializing
nda = DocumentArray.from_protobuf(pb)
trial_images = nda['@.[trial_images]c']

Hope this can help you to add a unitest to cover this issue

Yeah about this.. This is a use case built by me, so I know there are other docarray bugs so I have to use other ways to traverse 🤣 . Was gonna raise another bug when my project finishes so.. I don't think I will have time adding unit tests to this, so if the team like @alaeddine-13 can help that'd be great. Cheers.

@alaeddine-13 alaeddine-13 merged commit 34d2534 into docarray:main Jun 13, 2022
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.

Multi-modal Document has a float position

3 participants