Skip to content

Commit 02abfbd

Browse files
committed
Fix tests
1 parent 7fd3b9c commit 02abfbd

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
@@ -64,6 +63,14 @@
6463
DATE3 = datetime.datetime.strptime("2019-06-10", "%Y-%m-%d").replace(tzinfo=datetime.timezone.utc)
6564

6665

66+
def get_numpy_vector(input_list: list) -> Any:
67+
try:
68+
import numpy as np
69+
return np.array(input_list)
70+
except ModuleNotFoundError:
71+
return input_list
72+
73+
6774
def test_insert_with_typed_dict_generic(
6875
collection_factory: CollectionFactory,
6976
collection_factory_get: CollectionFactoryGet,
@@ -302,21 +309,21 @@ class TestInsertManyWithTypedDict(TypedDict):
302309
[
303310
(
304311
[
305-
DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])),
312+
DataObject(properties={"name": "some numpy one"}, vector=get_numpy_vector([1, 2, 3])),
306313
],
307314
False,
308315
),
309316
(
310317
[
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])),
318+
DataObject(properties={"name": "some numpy one"}, vector=get_numpy_vector([1, 2, 3])),
319+
DataObject(properties={"name": "some numpy two"}, vector=get_numpy_vector([11, 12, 13])),
313320
],
314321
False,
315322
),
316323
(
317324
[
318325
DataObject(
319-
properties={"name": "some numpy 2d"}, vector=np.array([[1, 2, 3], [11, 12, 13]])
326+
properties={"name": "some numpy 2d"}, vector=get_numpy_vector([[1, 2, 3], [11, 12, 13]])
320327
),
321328
],
322329
True,
@@ -328,6 +335,8 @@ def test_insert_many_with_numpy(
328335
objects: Sequence[DataObject[WeaviateProperties, Any]],
329336
should_error: bool,
330337
) -> None:
338+
if isinstance(objects[0].vector, list):
339+
pytest.skip("numpy not available")
331340
collection = collection_factory(
332341
properties=[Property(name="Name", data_type=DataType.TEXT)],
333342
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)