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

Method test_with_array_fields

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

Source from the content-addressed store, hash-verified

84 assert cpp_doc.get_any("is_male", DataType.BOOL) == True
85
86 def test_with_array_fields(self):
87 schema = CollectionSchema(
88 name="test_collection",
89 fields=[
90 FieldSchema("tags", DataType.ARRAY_STRING),
91 FieldSchema("ids", DataType.ARRAY_UINT64),
92 FieldSchema("marks", DataType.ARRAY_UINT32),
93 FieldSchema("x", DataType.ARRAY_INT32),
94 FieldSchema("y", DataType.ARRAY_INT64),
95 FieldSchema("scores", DataType.ARRAY_FLOAT),
96 FieldSchema("ratios", DataType.ARRAY_DOUBLE),
97 FieldSchema("results", DataType.ARRAY_BOOL),
98 ],
99 )
100
101 doc = Doc(
102 id="1",
103 fields={
104 "tags": ["tag1", "tag2", "tag3"],
105 "ids": [111111111111, 222222222222, 333333333333],
106 "marks": [100, 200, 300],
107 "x": [1, 2, 3],
108 "y": [100, 200, 300],
109 "scores": [1.1, 2.2, 3.3],
110 "ratios": [0.1, 0.2, 0.3],
111 "results": [True, False, True],
112 },
113 )
114 cpp_doc = convert_to_cpp_doc(doc, collection_schema=schema)
115
116 assert cpp_doc is not None
117 assert cpp_doc.pk() == doc.id
118 assert cpp_doc.get_any("tags", DataType.ARRAY_STRING) == doc.field("tags")
119 assert cpp_doc.get_any("ids", DataType.ARRAY_UINT64) == doc.field("ids")
120 assert cpp_doc.get_any("marks", DataType.ARRAY_UINT32) == doc.field("marks")
121 assert cpp_doc.get_any("x", DataType.ARRAY_INT32) == doc.field("x")
122 assert cpp_doc.get_any("y", DataType.ARRAY_INT64) == doc.field("y")
123 scores = cpp_doc.get_any("scores", DataType.ARRAY_FLOAT)
124 for i in range(len(doc.field("scores"))):
125 assert math.isclose(scores[i], doc.field("scores")[i], rel_tol=1e-1)
126 ratios = cpp_doc.get_any("ratios", DataType.ARRAY_DOUBLE)
127 for i in range(len(doc.field("ratios"))):
128 assert math.isclose(ratios[i], doc.field("ratios")[i], rel_tol=1e-1)
129 results = cpp_doc.get_any("results", DataType.ARRAY_BOOL)
130 for i in range(len(doc.field("results"))):
131 assert results[i] == doc.field("results")[i]
132
133 def test_with_dense_vector_fields(self):
134 schema = CollectionSchema(

Callers

nothing calls this directly

Calls 6

fieldMethod · 0.95
CollectionSchemaClass · 0.90
FieldSchemaClass · 0.90
DocClass · 0.90
convert_to_cpp_docFunction · 0.90
pkMethod · 0.80

Tested by

no test coverage detected