Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-reiss committed Jul 25, 2024
1 parent 7fd3b9c commit 02abfbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions integration/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion weaviate/collections/batch/grpc_batch_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 02abfbd

Please sign in to comment.