6
6
import uuid
7
7
from typing import Any , Callable , Dict , List , Optional , Sequence , TypedDict , Union
8
8
9
- import numpy as np
10
9
import pytest
11
10
12
11
from integration .conftest import CollectionFactory , CollectionFactoryGet , _sanitize_collection_name
64
63
DATE3 = datetime .datetime .strptime ("2019-06-10" , "%Y-%m-%d" ).replace (tzinfo = datetime .timezone .utc )
65
64
66
65
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
+
67
74
def test_insert_with_typed_dict_generic (
68
75
collection_factory : CollectionFactory ,
69
76
collection_factory_get : CollectionFactoryGet ,
@@ -302,21 +309,21 @@ class TestInsertManyWithTypedDict(TypedDict):
302
309
[
303
310
(
304
311
[
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 ])),
306
313
],
307
314
False ,
308
315
),
309
316
(
310
317
[
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 ])),
313
320
],
314
321
False ,
315
322
),
316
323
(
317
324
[
318
325
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 ]])
320
327
),
321
328
],
322
329
True ,
@@ -328,6 +335,8 @@ def test_insert_many_with_numpy(
328
335
objects : Sequence [DataObject [WeaviateProperties , Any ]],
329
336
should_error : bool ,
330
337
) -> None :
338
+ if isinstance (objects [0 ].vector , list ):
339
+ pytest .skip ("numpy not available" )
331
340
collection = collection_factory (
332
341
properties = [Property (name = "Name" , data_type = DataType .TEXT )],
333
342
vectorizer_config = Configure .Vectorizer .none (),
0 commit comments