Skip to content

Commit fa9f776

Browse files
committed
Fix tests
1 parent af1030b commit fa9f776

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

integration/test_collection.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import uuid
77
from typing import Any, Callable, Dict, List, Optional, Sequence, TypedDict, Union
88

9-
import numpy as np
109
import pytest
1110

1211
from integration.conftest import CollectionFactory, CollectionFactoryGet, _sanitize_collection_name
@@ -62,6 +61,14 @@
6261
DATE3 = datetime.datetime.strptime("2019-06-10", "%Y-%m-%d").replace(tzinfo=datetime.timezone.utc)
6362

6463

64+
def get_numpy_vector(input_list: list) -> Any:
65+
try:
66+
import numpy as np
67+
return np.array(input_list)
68+
except ModuleNotFoundError:
69+
return input_list
70+
71+
6572
def test_insert_with_typed_dict_generic(
6673
collection_factory: CollectionFactory,
6774
collection_factory_get: CollectionFactoryGet,
@@ -300,21 +307,21 @@ class TestInsertManyWithTypedDict(TypedDict):
300307
[
301308
(
302309
[
303-
DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])),
310+
DataObject(properties={"name": "some numpy one"}, vector=get_numpy_vector([1, 2, 3])),
304311
],
305312
False,
306313
),
307314
(
308315
[
309-
DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])),
310-
DataObject(properties={"name": "some numpy two"}, vector=np.array([11, 12, 13])),
316+
DataObject(properties={"name": "some numpy one"}, vector=get_numpy_vector([1, 2, 3])),
317+
DataObject(properties={"name": "some numpy two"}, vector=get_numpy_vector([11, 12, 13])),
311318
],
312319
False,
313320
),
314321
(
315322
[
316323
DataObject(
317-
properties={"name": "some numpy 2d"}, vector=np.array([[1, 2, 3], [11, 12, 13]])
324+
properties={"name": "some numpy 2d"}, vector=get_numpy_vector([[1, 2, 3], [11, 12, 13]])
318325
),
319326
],
320327
True,
@@ -326,6 +333,8 @@ def test_insert_many_with_numpy(
326333
objects: Sequence[DataObject[WeaviateProperties, Any]],
327334
should_error: bool,
328335
) -> None:
336+
if isinstance(objects[0].vector, list):
337+
pytest.skip("numpy not available")
329338
collection = collection_factory(
330339
properties=[Property(name="Name", data_type=DataType.TEXT)],
331340
vectorizer_config=Configure.Vectorizer.none(),

weaviate/collections/batch/grpc_batch_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def pack_vector(vector: Any) -> bytes:
5757
collection=obj.collection,
5858
vector_bytes=(
5959
pack_vector(obj.vector)
60-
if obj.vector is not None
60+
if obj.vector is not None and not isinstance(obj.vector, dict)
6161
else None
6262
),
6363
uuid=str(obj.uuid) if obj.uuid is not None else str(uuid_package.uuid4()),

0 commit comments

Comments
 (0)