Skip to content

Commit a0470c0

Browse files
author
Joan Fontanals Martinez
committed
test: add test showing error PydanticModel
1 parent 86b03f3 commit a0470c0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/unit/test_pydantic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,17 @@ def test_match_to_from_pydantic():
111111
assert da_r[0].matches[0].scores['cosine']
112112
assert isinstance(da_r[0].matches[0].scores, defaultdict)
113113
assert isinstance(da_r[0].matches[0].scores['random_score'], NamedScore)
114+
115+
116+
def test_pydantic_from_dict_ndarray():
117+
from docarray import Document
118+
import numpy as np
119+
doc = Document()
120+
doc.embedding = np.random.rand(2, 2)
121+
pydantic_model1 = doc.to_pydantic_model()
122+
assert len(pydantic_model1.embedding) == 2
123+
for emb_dim in pydantic_model1.embedding:
124+
assert len(emb_dim) == 2
125+
pydantic_model2 = PydanticDocument(**doc.to_dict())
126+
print(pydantic_model2.embedding)
127+

0 commit comments

Comments
 (0)