MCPcopy Create free account
hub / github.com/alibaba/zvec / test_with_array_fields

Method test_with_array_fields

python/tests/test_convert.py:448–497  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

446 assert py_doc.field("is_male") == True
447
448 def test_with_array_fields(self):
449 schema = CollectionSchema(
450 name="test_collection",
451 fields=[
452 FieldSchema("tags", DataType.ARRAY_STRING),
453 FieldSchema("ids", DataType.ARRAY_UINT64),
454 FieldSchema("marks", DataType.ARRAY_UINT32),
455 FieldSchema("x", DataType.ARRAY_INT32),
456 FieldSchema("y", DataType.ARRAY_INT64),
457 FieldSchema("scores", DataType.ARRAY_FLOAT),
458 FieldSchema("ratios", DataType.ARRAY_DOUBLE),
459 FieldSchema("results", DataType.ARRAY_BOOL),
460 ],
461 )
462
463 doc = _Doc()
464 doc.set_pk("1")
465 doc.set_any(
466 "tags", schema.field("tags")._get_object(), ["tag1", "tag2", "tag3"]
467 )
468 doc.set_any(
469 "ids",
470 schema.field("ids")._get_object(),
471 [111111111111, 222222222222, 3333333333333],
472 )
473 doc.set_any("marks", schema.field("marks")._get_object(), [1000, 2000, 3000])
474 doc.set_any("x", schema.field("x")._get_object(), [1, 2, 3])
475 doc.set_any("y", schema.field("y")._get_object(), [100, 200, 300])
476 doc.set_any("scores", schema.field("scores")._get_object(), [0.1, 0.2, 0.3])
477 doc.set_any("ratios", schema.field("ratios")._get_object(), [0.1, 0.2, 0.3])
478 doc.set_any(
479 "results", schema.field("results")._get_object(), [True, False, True]
480 )
481
482 py_doc = convert_to_py_doc(doc, schema)
483 assert py_doc.field("tags") == ["tag1", "tag2", "tag3"]
484 assert py_doc.field("ids") == [111111111111, 222222222222, 3333333333333]
485 assert py_doc.field("marks") == [1000, 2000, 3000]
486 assert py_doc.field("x") == [1, 2, 3]
487 assert py_doc.field("y") == [100, 200, 300]
488
489 scores = doc.get_any("scores", DataType.ARRAY_FLOAT)
490 for i in range(len(scores)):
491 assert math.isclose(scores[i], py_doc.field("scores")[i], rel_tol=1e-1)
492 ratios = doc.get_any("ratios", DataType.ARRAY_DOUBLE)
493 for i in range(len(ratios)):
494 assert math.isclose(ratios[i], py_doc.field("ratios")[i], rel_tol=1e-1)
495 results = doc.get_any("results", DataType.ARRAY_BOOL)
496 for i in range(len(results)):
497 assert results[i] == py_doc.field("results")[i]
498
499 def test_with_dense_vector_fields(self):
500 schema = CollectionSchema(

Callers

nothing calls this directly

Calls 6

fieldMethod · 0.95
CollectionSchemaClass · 0.90
FieldSchemaClass · 0.90
convert_to_py_docFunction · 0.90
_get_objectMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected