FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: skip annotations if not in __fields__ by NarekA · Pull Request #1779 · docarray/docarray · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions docarray/utils/create_dynamic_doc_class.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class MyDoc(BaseDoc):
"""
fields: Dict[str, Any] = {}
for field_name, field in model.__annotations__.items():
if field_name not in model.__fields__:
continue
field_info = model.__fields__[field_name].field_info
try:
if safe_issubclass(field, DocList):
Expand Down
8 changes: 7 additions & 1 deletion tests/units/util/test_create_dynamic_code_class.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union, ClassVar

import numpy as np
import pytest
Expand All @@ -17,9 +17,11 @@
def test_create_pydantic_model_from_schema(transformation):
class Nested2Doc(BaseDoc):
value: str
classvar: ClassVar[str] = 'classvar2'

class Nested1Doc(BaseDoc):
nested: Nested2Doc
classvar: ClassVar[str] = 'classvar1'

class CustomDoc(BaseDoc):
tensor: Optional[AnyTensor]
Expand All @@ -34,6 +36,7 @@ class CustomDoc(BaseDoc):
lu: List[Union[str, int]] = [0, 1, 2]
tags: Optional[Dict[str, Any]] = None
nested: Nested1Doc
classvar: ClassVar[str] = 'classvar'

CustomDocCopy = create_pure_python_type_model(CustomDoc)
new_custom_doc_model = create_base_doc_from_schema(
Expand Down Expand Up @@ -87,6 +90,9 @@ class CustomDoc(BaseDoc):
assert custom_partial_da[0].single_text.text == 'single hey ha'
assert custom_partial_da[0].single_text.embedding.shape == (2,)
assert original_back[0].nested.nested.value == 'hello world'
assert original_back[0].classvar == 'classvar'
assert original_back[0].nested.classvar == 'classvar1'
assert original_back[0].nested.nested.classvar == 'classvar2'

assert len(original_back) == 1
assert original_back[0].url == 'photo.jpg'
Expand Down

Back | FazBrowse Home | New Git URL