|
1 | 1 | import datetime
|
2 | 2 | import io
|
3 | 3 | import pathlib
|
| 4 | +import struct |
4 | 5 | import time
|
5 | 6 | import uuid
|
6 | 7 | from typing import Any, Callable, Dict, List, Optional, Sequence, TypedDict, Union
|
7 | 8 |
|
| 9 | +import numpy as np |
8 | 10 | import pytest
|
9 | 11 |
|
10 | 12 | from integration.conftest import CollectionFactory, CollectionFactoryGet, _sanitize_collection_name
|
@@ -295,6 +297,54 @@ class TestInsertManyWithTypedDict(TypedDict):
|
295 | 297 | assert obj2.properties["name"] == "some other name"
|
296 | 298 |
|
297 | 299 |
|
| 300 | +@pytest.mark.parametrize( |
| 301 | + "objects, should_error", |
| 302 | + [ |
| 303 | + ( |
| 304 | + [ |
| 305 | + DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])), |
| 306 | + ], |
| 307 | + False, |
| 308 | + ), |
| 309 | + ( |
| 310 | + [ |
| 311 | + DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])), |
| 312 | + DataObject(properties={"name": "some numpy two"}, vector=np.array([11, 12, 13])), |
| 313 | + ], |
| 314 | + False, |
| 315 | + ), |
| 316 | + ( |
| 317 | + [ |
| 318 | + DataObject( |
| 319 | + properties={"name": "some numpy 2d"}, vector=np.array([[1, 2, 3], [11, 12, 13]]) |
| 320 | + ), |
| 321 | + ], |
| 322 | + True, |
| 323 | + ), |
| 324 | + ], |
| 325 | +) |
| 326 | +def test_insert_many_with_numpy( |
| 327 | + collection_factory: CollectionFactory, |
| 328 | + objects: Sequence[DataObject[WeaviateProperties, Any]], |
| 329 | + should_error: bool, |
| 330 | +) -> None: |
| 331 | + collection = collection_factory( |
| 332 | + properties=[Property(name="Name", data_type=DataType.TEXT)], |
| 333 | + vectorizer_config=Configure.Vectorizer.none(), |
| 334 | + ) |
| 335 | + if not should_error: |
| 336 | + ret = collection.data.insert_many(objects) |
| 337 | + for idx, uuid_ in ret.uuids.items(): |
| 338 | + obj1 = collection.query.fetch_object_by_id(uuid_, include_vector=True) |
| 339 | + inserted = objects[idx] |
| 340 | + assert inserted.properties["name"] == obj1.properties["name"] |
| 341 | + assert inserted.vector.tolist() == obj1.vector["default"] # type: ignore[union-attr] |
| 342 | + else: |
| 343 | + with pytest.raises(struct.error) as e: |
| 344 | + collection.data.insert_many(objects) |
| 345 | + assert str(e.value) == "required argument is not a float" |
| 346 | + |
| 347 | + |
298 | 348 | def test_insert_many_with_refs(collection_factory: CollectionFactory) -> None:
|
299 | 349 | ref_collection = collection_factory(
|
300 | 350 | name="target", vectorizer_config=Configure.Vectorizer.none()
|
|
0 commit comments