Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/unit/test_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,17 @@ def test_match_to_from_pydantic():
assert da_r[0].matches[0].scores['cosine']
assert isinstance(da_r[0].matches[0].scores, defaultdict)
assert isinstance(da_r[0].matches[0].scores['random_score'], NamedScore)


def test_pydantic_from_dict_ndarray():
from docarray import Document
import numpy as np
doc = Document()
doc.embedding = np.random.rand(2, 2)
pydantic_model1 = doc.to_pydantic_model()
assert len(pydantic_model1.embedding) == 2
for emb_dim in pydantic_model1.embedding:
assert len(emb_dim) == 2
pydantic_model2 = PydanticDocument(**doc.to_dict())
print(pydantic_model2.embedding)