From 02abfbd5147831b37358485730656cc783221287 Mon Sep 17 00:00:00 2001 From: Tibor Reiss <tibor.reiss@gmail.com> Date: Thu, 25 Jul 2024 21:39:25 +0200 Subject: [PATCH] Fix tests --- integration/test_collection.py | 19 ++++++++++++++----- .../collections/batch/grpc_batch_objects.py | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/integration/test_collection.py b/integration/test_collection.py index 605a1918c..2f3cb2184 100644 --- a/integration/test_collection.py +++ b/integration/test_collection.py @@ -6,7 +6,6 @@ import uuid from typing import Any, Callable, Dict, List, Optional, Sequence, TypedDict, Union -import numpy as np import pytest from integration.conftest import CollectionFactory, CollectionFactoryGet, _sanitize_collection_name @@ -64,6 +63,14 @@ DATE3 = datetime.datetime.strptime("2019-06-10", "%Y-%m-%d").replace(tzinfo=datetime.timezone.utc) +def get_numpy_vector(input_list: list) -> Any: + try: + import numpy as np + return np.array(input_list) + except ModuleNotFoundError: + return input_list + + def test_insert_with_typed_dict_generic( collection_factory: CollectionFactory, collection_factory_get: CollectionFactoryGet, @@ -302,21 +309,21 @@ class TestInsertManyWithTypedDict(TypedDict): [ ( [ - DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])), + DataObject(properties={"name": "some numpy one"}, vector=get_numpy_vector([1, 2, 3])), ], False, ), ( [ - DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])), - DataObject(properties={"name": "some numpy two"}, vector=np.array([11, 12, 13])), + DataObject(properties={"name": "some numpy one"}, vector=get_numpy_vector([1, 2, 3])), + DataObject(properties={"name": "some numpy two"}, vector=get_numpy_vector([11, 12, 13])), ], False, ), ( [ DataObject( - properties={"name": "some numpy 2d"}, vector=np.array([[1, 2, 3], [11, 12, 13]]) + properties={"name": "some numpy 2d"}, vector=get_numpy_vector([[1, 2, 3], [11, 12, 13]]) ), ], True, @@ -328,6 +335,8 @@ def test_insert_many_with_numpy( objects: Sequence[DataObject[WeaviateProperties, Any]], should_error: bool, ) -> None: + if isinstance(objects[0].vector, list): + pytest.skip("numpy not available") collection = collection_factory( properties=[Property(name="Name", data_type=DataType.TEXT)], vectorizer_config=Configure.Vectorizer.none(), diff --git a/weaviate/collections/batch/grpc_batch_objects.py b/weaviate/collections/batch/grpc_batch_objects.py index ed2dad479..f5008cb31 100644 --- a/weaviate/collections/batch/grpc_batch_objects.py +++ b/weaviate/collections/batch/grpc_batch_objects.py @@ -57,7 +57,7 @@ def pack_vector(vector: Any) -> bytes: collection=obj.collection, vector_bytes=( pack_vector(obj.vector) - if obj.vector is not None + if obj.vector is not None and not isinstance(obj.vector, dict) else None ), uuid=str(obj.uuid) if obj.uuid is not None else str(uuid_package.uuid4()),