cocoindex 0.1.50__cp312-cp312-win_amd64.whl → 0.1.51__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cocoindex/__init__.py +51 -0
- cocoindex/_engine.cp312-win_amd64.pyd +0 -0
- cocoindex/cli.py +22 -4
- cocoindex/convert.py +7 -3
- cocoindex/setting.py +10 -6
- cocoindex/tests/test_convert.py +151 -104
- cocoindex/tests/test_optional_database.py +249 -0
- cocoindex/tests/test_typing.py +62 -56
- cocoindex/typing.py +19 -19
- {cocoindex-0.1.50.dist-info → cocoindex-0.1.51.dist-info}/METADATA +1 -1
- {cocoindex-0.1.50.dist-info → cocoindex-0.1.51.dist-info}/RECORD +14 -13
- {cocoindex-0.1.50.dist-info → cocoindex-0.1.51.dist-info}/WHEEL +0 -0
- {cocoindex-0.1.50.dist-info → cocoindex-0.1.51.dist-info}/entry_points.txt +0 -0
- {cocoindex-0.1.50.dist-info → cocoindex-0.1.51.dist-info}/licenses/LICENSE +0 -0
cocoindex/tests/test_typing.py
CHANGED
@@ -39,7 +39,7 @@ class SimpleNamedTuple(NamedTuple):
|
|
39
39
|
value: Any
|
40
40
|
|
41
41
|
|
42
|
-
def test_ndarray_float32_no_dim():
|
42
|
+
def test_ndarray_float32_no_dim() -> None:
|
43
43
|
typ = NDArray[np.float32]
|
44
44
|
result = analyze_type_info(typ)
|
45
45
|
assert result == AnalyzedTypeInfo(
|
@@ -48,12 +48,13 @@ def test_ndarray_float32_no_dim():
|
|
48
48
|
elem_type=Float32,
|
49
49
|
key_type=None,
|
50
50
|
struct_type=None,
|
51
|
+
np_number_type=np.float32,
|
51
52
|
attrs=None,
|
52
53
|
nullable=False,
|
53
54
|
)
|
54
55
|
|
55
56
|
|
56
|
-
def test_vector_float32_no_dim():
|
57
|
+
def test_vector_float32_no_dim() -> None:
|
57
58
|
typ = Vector[np.float32]
|
58
59
|
result = analyze_type_info(typ)
|
59
60
|
assert result == AnalyzedTypeInfo(
|
@@ -62,12 +63,13 @@ def test_vector_float32_no_dim():
|
|
62
63
|
elem_type=Float32,
|
63
64
|
key_type=None,
|
64
65
|
struct_type=None,
|
66
|
+
np_number_type=np.float32,
|
65
67
|
attrs=None,
|
66
68
|
nullable=False,
|
67
69
|
)
|
68
70
|
|
69
71
|
|
70
|
-
def test_ndarray_float64_with_dim():
|
72
|
+
def test_ndarray_float64_with_dim() -> None:
|
71
73
|
typ = Annotated[NDArray[np.float64], VectorInfo(dim=128)]
|
72
74
|
result = analyze_type_info(typ)
|
73
75
|
assert result == AnalyzedTypeInfo(
|
@@ -76,12 +78,13 @@ def test_ndarray_float64_with_dim():
|
|
76
78
|
elem_type=Float64,
|
77
79
|
key_type=None,
|
78
80
|
struct_type=None,
|
81
|
+
np_number_type=np.float64,
|
79
82
|
attrs=None,
|
80
83
|
nullable=False,
|
81
84
|
)
|
82
85
|
|
83
86
|
|
84
|
-
def test_vector_float32_with_dim():
|
87
|
+
def test_vector_float32_with_dim() -> None:
|
85
88
|
typ = Vector[np.float32, Literal[384]]
|
86
89
|
result = analyze_type_info(typ)
|
87
90
|
assert result == AnalyzedTypeInfo(
|
@@ -90,12 +93,13 @@ def test_vector_float32_with_dim():
|
|
90
93
|
elem_type=Float32,
|
91
94
|
key_type=None,
|
92
95
|
struct_type=None,
|
96
|
+
np_number_type=np.float32,
|
93
97
|
attrs=None,
|
94
98
|
nullable=False,
|
95
99
|
)
|
96
100
|
|
97
101
|
|
98
|
-
def test_ndarray_int64_no_dim():
|
102
|
+
def test_ndarray_int64_no_dim() -> None:
|
99
103
|
typ = NDArray[np.int64]
|
100
104
|
result = analyze_type_info(typ)
|
101
105
|
assert result.kind == "Vector"
|
@@ -104,25 +108,7 @@ def test_ndarray_int64_no_dim():
|
|
104
108
|
assert not result.nullable
|
105
109
|
|
106
110
|
|
107
|
-
def
|
108
|
-
typ = Annotated[NDArray[np.int32], VectorInfo(dim=10)]
|
109
|
-
result = analyze_type_info(typ)
|
110
|
-
assert result.kind == "Vector"
|
111
|
-
assert result.vector_info == VectorInfo(dim=10)
|
112
|
-
assert get_args(result.elem_type) == (int, TypeKind("Int32"))
|
113
|
-
assert not result.nullable
|
114
|
-
|
115
|
-
|
116
|
-
def test_ndarray_uint8_no_dim():
|
117
|
-
typ = NDArray[np.uint8]
|
118
|
-
result = analyze_type_info(typ)
|
119
|
-
assert result.kind == "Vector"
|
120
|
-
assert result.vector_info == VectorInfo(dim=None)
|
121
|
-
assert get_args(result.elem_type) == (int, TypeKind("UInt8"))
|
122
|
-
assert not result.nullable
|
123
|
-
|
124
|
-
|
125
|
-
def test_nullable_ndarray():
|
111
|
+
def test_nullable_ndarray() -> None:
|
126
112
|
typ = NDArray[np.float32] | None
|
127
113
|
result = analyze_type_info(typ)
|
128
114
|
assert result == AnalyzedTypeInfo(
|
@@ -131,12 +117,13 @@ def test_nullable_ndarray():
|
|
131
117
|
elem_type=Float32,
|
132
118
|
key_type=None,
|
133
119
|
struct_type=None,
|
120
|
+
np_number_type=np.float32,
|
134
121
|
attrs=None,
|
135
122
|
nullable=True,
|
136
123
|
)
|
137
124
|
|
138
125
|
|
139
|
-
def test_vector_str():
|
126
|
+
def test_vector_str() -> None:
|
140
127
|
typ = Vector[str]
|
141
128
|
result = analyze_type_info(typ)
|
142
129
|
assert result.kind == "Vector"
|
@@ -144,7 +131,7 @@ def test_vector_str():
|
|
144
131
|
assert result.vector_info == VectorInfo(dim=None)
|
145
132
|
|
146
133
|
|
147
|
-
def test_vector_complex64():
|
134
|
+
def test_vector_complex64() -> None:
|
148
135
|
typ = Vector[np.complex64]
|
149
136
|
result = analyze_type_info(typ)
|
150
137
|
assert result.kind == "Vector"
|
@@ -152,7 +139,7 @@ def test_vector_complex64():
|
|
152
139
|
assert result.vector_info == VectorInfo(dim=None)
|
153
140
|
|
154
141
|
|
155
|
-
def test_non_numpy_vector():
|
142
|
+
def test_non_numpy_vector() -> None:
|
156
143
|
typ = Vector[float, Literal[3]]
|
157
144
|
result = analyze_type_info(typ)
|
158
145
|
assert result.kind == "Vector"
|
@@ -160,7 +147,7 @@ def test_non_numpy_vector():
|
|
160
147
|
assert result.vector_info == VectorInfo(dim=3)
|
161
148
|
|
162
149
|
|
163
|
-
def test_ndarray_any_dtype():
|
150
|
+
def test_ndarray_any_dtype() -> None:
|
164
151
|
typ = NDArray[Any]
|
165
152
|
with pytest.raises(
|
166
153
|
TypeError, match="NDArray for Vector must use a concrete numpy dtype"
|
@@ -168,7 +155,7 @@ def test_ndarray_any_dtype():
|
|
168
155
|
analyze_type_info(typ)
|
169
156
|
|
170
157
|
|
171
|
-
def test_list_of_primitives():
|
158
|
+
def test_list_of_primitives() -> None:
|
172
159
|
typ = List[str]
|
173
160
|
result = analyze_type_info(typ)
|
174
161
|
assert result == AnalyzedTypeInfo(
|
@@ -177,12 +164,13 @@ def test_list_of_primitives():
|
|
177
164
|
elem_type=str,
|
178
165
|
key_type=None,
|
179
166
|
struct_type=None,
|
167
|
+
np_number_type=None,
|
180
168
|
attrs=None,
|
181
169
|
nullable=False,
|
182
170
|
)
|
183
171
|
|
184
172
|
|
185
|
-
def test_list_of_structs():
|
173
|
+
def test_list_of_structs() -> None:
|
186
174
|
typ = List[SimpleDataclass]
|
187
175
|
result = analyze_type_info(typ)
|
188
176
|
assert result == AnalyzedTypeInfo(
|
@@ -191,12 +179,13 @@ def test_list_of_structs():
|
|
191
179
|
elem_type=SimpleDataclass,
|
192
180
|
key_type=None,
|
193
181
|
struct_type=None,
|
182
|
+
np_number_type=None,
|
194
183
|
attrs=None,
|
195
184
|
nullable=False,
|
196
185
|
)
|
197
186
|
|
198
187
|
|
199
|
-
def test_sequence_of_int():
|
188
|
+
def test_sequence_of_int() -> None:
|
200
189
|
typ = Sequence[int]
|
201
190
|
result = analyze_type_info(typ)
|
202
191
|
assert result == AnalyzedTypeInfo(
|
@@ -205,12 +194,13 @@ def test_sequence_of_int():
|
|
205
194
|
elem_type=int,
|
206
195
|
key_type=None,
|
207
196
|
struct_type=None,
|
197
|
+
np_number_type=None,
|
208
198
|
attrs=None,
|
209
199
|
nullable=False,
|
210
200
|
)
|
211
201
|
|
212
202
|
|
213
|
-
def test_list_with_vector_info():
|
203
|
+
def test_list_with_vector_info() -> None:
|
214
204
|
typ = Annotated[List[int], VectorInfo(dim=5)]
|
215
205
|
result = analyze_type_info(typ)
|
216
206
|
assert result == AnalyzedTypeInfo(
|
@@ -219,12 +209,13 @@ def test_list_with_vector_info():
|
|
219
209
|
elem_type=int,
|
220
210
|
key_type=None,
|
221
211
|
struct_type=None,
|
212
|
+
np_number_type=None,
|
222
213
|
attrs=None,
|
223
214
|
nullable=False,
|
224
215
|
)
|
225
216
|
|
226
217
|
|
227
|
-
def test_dict_str_int():
|
218
|
+
def test_dict_str_int() -> None:
|
228
219
|
typ = Dict[str, int]
|
229
220
|
result = analyze_type_info(typ)
|
230
221
|
assert result == AnalyzedTypeInfo(
|
@@ -233,12 +224,13 @@ def test_dict_str_int():
|
|
233
224
|
elem_type=(str, int),
|
234
225
|
key_type=None,
|
235
226
|
struct_type=None,
|
227
|
+
np_number_type=None,
|
236
228
|
attrs=None,
|
237
229
|
nullable=False,
|
238
230
|
)
|
239
231
|
|
240
232
|
|
241
|
-
def test_mapping_str_dataclass():
|
233
|
+
def test_mapping_str_dataclass() -> None:
|
242
234
|
typ = Mapping[str, SimpleDataclass]
|
243
235
|
result = analyze_type_info(typ)
|
244
236
|
assert result == AnalyzedTypeInfo(
|
@@ -247,12 +239,13 @@ def test_mapping_str_dataclass():
|
|
247
239
|
elem_type=(str, SimpleDataclass),
|
248
240
|
key_type=None,
|
249
241
|
struct_type=None,
|
242
|
+
np_number_type=None,
|
250
243
|
attrs=None,
|
251
244
|
nullable=False,
|
252
245
|
)
|
253
246
|
|
254
247
|
|
255
|
-
def test_dataclass():
|
248
|
+
def test_dataclass() -> None:
|
256
249
|
typ = SimpleDataclass
|
257
250
|
result = analyze_type_info(typ)
|
258
251
|
assert result == AnalyzedTypeInfo(
|
@@ -261,12 +254,13 @@ def test_dataclass():
|
|
261
254
|
elem_type=None,
|
262
255
|
key_type=None,
|
263
256
|
struct_type=SimpleDataclass,
|
257
|
+
np_number_type=None,
|
264
258
|
attrs=None,
|
265
259
|
nullable=False,
|
266
260
|
)
|
267
261
|
|
268
262
|
|
269
|
-
def test_named_tuple():
|
263
|
+
def test_named_tuple() -> None:
|
270
264
|
typ = SimpleNamedTuple
|
271
265
|
result = analyze_type_info(typ)
|
272
266
|
assert result == AnalyzedTypeInfo(
|
@@ -275,12 +269,13 @@ def test_named_tuple():
|
|
275
269
|
elem_type=None,
|
276
270
|
key_type=None,
|
277
271
|
struct_type=SimpleNamedTuple,
|
272
|
+
np_number_type=None,
|
278
273
|
attrs=None,
|
279
274
|
nullable=False,
|
280
275
|
)
|
281
276
|
|
282
277
|
|
283
|
-
def test_tuple_key_value():
|
278
|
+
def test_tuple_key_value() -> None:
|
284
279
|
typ = (str, int)
|
285
280
|
result = analyze_type_info(typ)
|
286
281
|
assert result == AnalyzedTypeInfo(
|
@@ -289,12 +284,13 @@ def test_tuple_key_value():
|
|
289
284
|
elem_type=None,
|
290
285
|
key_type=str,
|
291
286
|
struct_type=None,
|
287
|
+
np_number_type=None,
|
292
288
|
attrs=None,
|
293
289
|
nullable=False,
|
294
290
|
)
|
295
291
|
|
296
292
|
|
297
|
-
def test_str():
|
293
|
+
def test_str() -> None:
|
298
294
|
typ = str
|
299
295
|
result = analyze_type_info(typ)
|
300
296
|
assert result == AnalyzedTypeInfo(
|
@@ -303,12 +299,13 @@ def test_str():
|
|
303
299
|
elem_type=None,
|
304
300
|
key_type=None,
|
305
301
|
struct_type=None,
|
302
|
+
np_number_type=None,
|
306
303
|
attrs=None,
|
307
304
|
nullable=False,
|
308
305
|
)
|
309
306
|
|
310
307
|
|
311
|
-
def test_bool():
|
308
|
+
def test_bool() -> None:
|
312
309
|
typ = bool
|
313
310
|
result = analyze_type_info(typ)
|
314
311
|
assert result == AnalyzedTypeInfo(
|
@@ -317,12 +314,13 @@ def test_bool():
|
|
317
314
|
elem_type=None,
|
318
315
|
key_type=None,
|
319
316
|
struct_type=None,
|
317
|
+
np_number_type=None,
|
320
318
|
attrs=None,
|
321
319
|
nullable=False,
|
322
320
|
)
|
323
321
|
|
324
322
|
|
325
|
-
def test_bytes():
|
323
|
+
def test_bytes() -> None:
|
326
324
|
typ = bytes
|
327
325
|
result = analyze_type_info(typ)
|
328
326
|
assert result == AnalyzedTypeInfo(
|
@@ -331,12 +329,13 @@ def test_bytes():
|
|
331
329
|
elem_type=None,
|
332
330
|
key_type=None,
|
333
331
|
struct_type=None,
|
332
|
+
np_number_type=None,
|
334
333
|
attrs=None,
|
335
334
|
nullable=False,
|
336
335
|
)
|
337
336
|
|
338
337
|
|
339
|
-
def test_uuid():
|
338
|
+
def test_uuid() -> None:
|
340
339
|
typ = uuid.UUID
|
341
340
|
result = analyze_type_info(typ)
|
342
341
|
assert result == AnalyzedTypeInfo(
|
@@ -345,12 +344,13 @@ def test_uuid():
|
|
345
344
|
elem_type=None,
|
346
345
|
key_type=None,
|
347
346
|
struct_type=None,
|
347
|
+
np_number_type=None,
|
348
348
|
attrs=None,
|
349
349
|
nullable=False,
|
350
350
|
)
|
351
351
|
|
352
352
|
|
353
|
-
def test_date():
|
353
|
+
def test_date() -> None:
|
354
354
|
typ = datetime.date
|
355
355
|
result = analyze_type_info(typ)
|
356
356
|
assert result == AnalyzedTypeInfo(
|
@@ -359,12 +359,13 @@ def test_date():
|
|
359
359
|
elem_type=None,
|
360
360
|
key_type=None,
|
361
361
|
struct_type=None,
|
362
|
+
np_number_type=None,
|
362
363
|
attrs=None,
|
363
364
|
nullable=False,
|
364
365
|
)
|
365
366
|
|
366
367
|
|
367
|
-
def test_time():
|
368
|
+
def test_time() -> None:
|
368
369
|
typ = datetime.time
|
369
370
|
result = analyze_type_info(typ)
|
370
371
|
assert result == AnalyzedTypeInfo(
|
@@ -373,12 +374,13 @@ def test_time():
|
|
373
374
|
elem_type=None,
|
374
375
|
key_type=None,
|
375
376
|
struct_type=None,
|
377
|
+
np_number_type=None,
|
376
378
|
attrs=None,
|
377
379
|
nullable=False,
|
378
380
|
)
|
379
381
|
|
380
382
|
|
381
|
-
def test_timedelta():
|
383
|
+
def test_timedelta() -> None:
|
382
384
|
typ = datetime.timedelta
|
383
385
|
result = analyze_type_info(typ)
|
384
386
|
assert result == AnalyzedTypeInfo(
|
@@ -387,12 +389,13 @@ def test_timedelta():
|
|
387
389
|
elem_type=None,
|
388
390
|
key_type=None,
|
389
391
|
struct_type=None,
|
392
|
+
np_number_type=None,
|
390
393
|
attrs=None,
|
391
394
|
nullable=False,
|
392
395
|
)
|
393
396
|
|
394
397
|
|
395
|
-
def test_float():
|
398
|
+
def test_float() -> None:
|
396
399
|
typ = float
|
397
400
|
result = analyze_type_info(typ)
|
398
401
|
assert result == AnalyzedTypeInfo(
|
@@ -401,12 +404,13 @@ def test_float():
|
|
401
404
|
elem_type=None,
|
402
405
|
key_type=None,
|
403
406
|
struct_type=None,
|
407
|
+
np_number_type=None,
|
404
408
|
attrs=None,
|
405
409
|
nullable=False,
|
406
410
|
)
|
407
411
|
|
408
412
|
|
409
|
-
def test_int():
|
413
|
+
def test_int() -> None:
|
410
414
|
typ = int
|
411
415
|
result = analyze_type_info(typ)
|
412
416
|
assert result == AnalyzedTypeInfo(
|
@@ -415,12 +419,13 @@ def test_int():
|
|
415
419
|
elem_type=None,
|
416
420
|
key_type=None,
|
417
421
|
struct_type=None,
|
422
|
+
np_number_type=None,
|
418
423
|
attrs=None,
|
419
424
|
nullable=False,
|
420
425
|
)
|
421
426
|
|
422
427
|
|
423
|
-
def test_type_with_attributes():
|
428
|
+
def test_type_with_attributes() -> None:
|
424
429
|
typ = Annotated[str, TypeAttr("key", "value")]
|
425
430
|
result = analyze_type_info(typ)
|
426
431
|
assert result == AnalyzedTypeInfo(
|
@@ -429,18 +434,19 @@ def test_type_with_attributes():
|
|
429
434
|
elem_type=None,
|
430
435
|
key_type=None,
|
431
436
|
struct_type=None,
|
437
|
+
np_number_type=None,
|
432
438
|
attrs={"key": "value"},
|
433
439
|
nullable=False,
|
434
440
|
)
|
435
441
|
|
436
442
|
|
437
|
-
def test_encode_enriched_type_none():
|
443
|
+
def test_encode_enriched_type_none() -> None:
|
438
444
|
typ = None
|
439
445
|
result = encode_enriched_type(typ)
|
440
446
|
assert result is None
|
441
447
|
|
442
448
|
|
443
|
-
def test_encode_enriched_type_struct():
|
449
|
+
def test_encode_enriched_type_struct() -> None:
|
444
450
|
typ = SimpleDataclass
|
445
451
|
result = encode_enriched_type(typ)
|
446
452
|
assert result["type"]["kind"] == "Struct"
|
@@ -451,7 +457,7 @@ def test_encode_enriched_type_struct():
|
|
451
457
|
assert result["type"]["fields"][1]["type"]["kind"] == "Int64"
|
452
458
|
|
453
459
|
|
454
|
-
def test_encode_enriched_type_vector():
|
460
|
+
def test_encode_enriched_type_vector() -> None:
|
455
461
|
typ = NDArray[np.float32]
|
456
462
|
result = encode_enriched_type(typ)
|
457
463
|
assert result["type"]["kind"] == "Vector"
|
@@ -459,7 +465,7 @@ def test_encode_enriched_type_vector():
|
|
459
465
|
assert result["type"]["dimension"] is None
|
460
466
|
|
461
467
|
|
462
|
-
def test_encode_enriched_type_ltable():
|
468
|
+
def test_encode_enriched_type_ltable() -> None:
|
463
469
|
typ = List[SimpleDataclass]
|
464
470
|
result = encode_enriched_type(typ)
|
465
471
|
assert result["type"]["kind"] == "LTable"
|
@@ -467,33 +473,33 @@ def test_encode_enriched_type_ltable():
|
|
467
473
|
assert len(result["type"]["row"]["fields"]) == 2
|
468
474
|
|
469
475
|
|
470
|
-
def test_encode_enriched_type_with_attrs():
|
476
|
+
def test_encode_enriched_type_with_attrs() -> None:
|
471
477
|
typ = Annotated[str, TypeAttr("key", "value")]
|
472
478
|
result = encode_enriched_type(typ)
|
473
479
|
assert result["type"]["kind"] == "Str"
|
474
480
|
assert result["attrs"] == {"key": "value"}
|
475
481
|
|
476
482
|
|
477
|
-
def test_encode_enriched_type_nullable():
|
483
|
+
def test_encode_enriched_type_nullable() -> None:
|
478
484
|
typ = str | None
|
479
485
|
result = encode_enriched_type(typ)
|
480
486
|
assert result["type"]["kind"] == "Str"
|
481
487
|
assert result["nullable"] is True
|
482
488
|
|
483
489
|
|
484
|
-
def test_invalid_struct_kind():
|
490
|
+
def test_invalid_struct_kind() -> None:
|
485
491
|
typ = Annotated[SimpleDataclass, TypeKind("Vector")]
|
486
492
|
with pytest.raises(ValueError, match="Unexpected type kind for struct: Vector"):
|
487
493
|
analyze_type_info(typ)
|
488
494
|
|
489
495
|
|
490
|
-
def test_invalid_list_kind():
|
496
|
+
def test_invalid_list_kind() -> None:
|
491
497
|
typ = Annotated[List[int], TypeKind("Struct")]
|
492
498
|
with pytest.raises(ValueError, match="Unexpected type kind for list: Struct"):
|
493
499
|
analyze_type_info(typ)
|
494
500
|
|
495
501
|
|
496
|
-
def test_unsupported_type():
|
502
|
+
def test_unsupported_type() -> None:
|
497
503
|
typ = set
|
498
504
|
with pytest.raises(ValueError, match="type unsupported yet: <class 'set'>"):
|
499
505
|
analyze_type_info(typ)
|
cocoindex/typing.py
CHANGED
@@ -49,7 +49,7 @@ OffsetDateTime = Annotated[datetime.datetime, TypeKind("OffsetDateTime")]
|
|
49
49
|
|
50
50
|
if TYPE_CHECKING:
|
51
51
|
T_co = TypeVar("T_co", covariant=True)
|
52
|
-
Dim_co = TypeVar("Dim_co", bound=int, covariant=True)
|
52
|
+
Dim_co = TypeVar("Dim_co", bound=int | None, covariant=True, default=None)
|
53
53
|
|
54
54
|
class Vector(Protocol, Generic[T_co, Dim_co]):
|
55
55
|
"""Vector[T, Dim] is a special typing alias for an NDArray[T] with optional dimension info"""
|
@@ -111,34 +111,29 @@ class DtypeInfo:
|
|
111
111
|
|
112
112
|
|
113
113
|
class DtypeRegistry:
|
114
|
+
"""
|
115
|
+
Registry for NumPy dtypes used in CocoIndex.
|
116
|
+
Provides mappings from NumPy dtypes to CocoIndex's type representation.
|
117
|
+
"""
|
118
|
+
|
114
119
|
_mappings: dict[type, DtypeInfo] = {
|
115
120
|
np.float32: DtypeInfo(np.float32, "Float32", float),
|
116
121
|
np.float64: DtypeInfo(np.float64, "Float64", float),
|
117
|
-
np.int32: DtypeInfo(np.int32, "Int32", int),
|
118
122
|
np.int64: DtypeInfo(np.int64, "Int64", int),
|
119
|
-
np.uint8: DtypeInfo(np.uint8, "UInt8", int),
|
120
|
-
np.uint16: DtypeInfo(np.uint16, "UInt16", int),
|
121
|
-
np.uint32: DtypeInfo(np.uint32, "UInt32", int),
|
122
|
-
np.uint64: DtypeInfo(np.uint64, "UInt64", int),
|
123
123
|
}
|
124
124
|
|
125
125
|
@classmethod
|
126
126
|
def get_by_dtype(cls, dtype: Any) -> DtypeInfo | None:
|
127
|
+
"""Get DtypeInfo by NumPy dtype."""
|
127
128
|
if dtype is Any:
|
128
129
|
raise TypeError(
|
129
130
|
"NDArray for Vector must use a concrete numpy dtype, got `Any`."
|
130
131
|
)
|
131
132
|
return cls._mappings.get(dtype)
|
132
133
|
|
133
|
-
@staticmethod
|
134
|
-
def get_by_kind(kind: str) -> DtypeInfo | None:
|
135
|
-
return next(
|
136
|
-
(info for info in DtypeRegistry._mappings.values() if info.kind == kind),
|
137
|
-
None,
|
138
|
-
)
|
139
|
-
|
140
134
|
@staticmethod
|
141
135
|
def supported_dtypes() -> KeysView[type]:
|
136
|
+
"""Get a list of supported NumPy dtypes."""
|
142
137
|
return DtypeRegistry._mappings.keys()
|
143
138
|
|
144
139
|
|
@@ -154,6 +149,9 @@ class AnalyzedTypeInfo:
|
|
154
149
|
|
155
150
|
key_type: type | None # For element of KTable
|
156
151
|
struct_type: type | None # For Struct, a dataclass or namedtuple
|
152
|
+
np_number_type: (
|
153
|
+
type | None
|
154
|
+
) # NumPy dtype for the element type, if represented by numpy.ndarray or a NumPy scalar
|
157
155
|
|
158
156
|
attrs: dict[str, Any] | None
|
159
157
|
nullable: bool = False
|
@@ -208,6 +206,7 @@ def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
|
|
208
206
|
struct_type: type | None = None
|
209
207
|
elem_type: ElementType | None = None
|
210
208
|
key_type: type | None = None
|
209
|
+
np_number_type: type | None = None
|
211
210
|
if _is_struct_type(t):
|
212
211
|
struct_type = t
|
213
212
|
|
@@ -241,11 +240,11 @@ def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
|
|
241
240
|
if not dtype_args:
|
242
241
|
raise ValueError("Invalid dtype specification for NDArray")
|
243
242
|
|
244
|
-
|
245
|
-
dtype_info = DtypeRegistry.get_by_dtype(
|
243
|
+
np_number_type = dtype_args[0]
|
244
|
+
dtype_info = DtypeRegistry.get_by_dtype(np_number_type)
|
246
245
|
if dtype_info is None:
|
247
246
|
raise ValueError(
|
248
|
-
f"Unsupported numpy dtype for NDArray: {
|
247
|
+
f"Unsupported numpy dtype for NDArray: {np_number_type}. "
|
249
248
|
f"Supported dtypes: {DtypeRegistry.supported_dtypes()}"
|
250
249
|
)
|
251
250
|
elem_type = dtype_info.annotated_type
|
@@ -259,6 +258,7 @@ def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
|
|
259
258
|
dtype_info = DtypeRegistry.get_by_dtype(t)
|
260
259
|
if dtype_info is not None:
|
261
260
|
kind = dtype_info.kind
|
261
|
+
np_number_type = dtype_info.numpy_dtype
|
262
262
|
elif t is bytes:
|
263
263
|
kind = "Bytes"
|
264
264
|
elif t is str:
|
@@ -288,6 +288,7 @@ def analyze_type_info(t: Any) -> AnalyzedTypeInfo:
|
|
288
288
|
elem_type=elem_type,
|
289
289
|
key_type=key_type,
|
290
290
|
struct_type=struct_type,
|
291
|
+
np_number_type=np_number_type,
|
291
292
|
attrs=attrs,
|
292
293
|
nullable=nullable,
|
293
294
|
)
|
@@ -340,9 +341,8 @@ def _encode_type(type_info: AnalyzedTypeInfo) -> dict[str, Any]:
|
|
340
341
|
raise ValueError("Vector type must have a vector info")
|
341
342
|
if type_info.elem_type is None:
|
342
343
|
raise ValueError("Vector type must have an element type")
|
343
|
-
|
344
|
-
|
345
|
-
)
|
344
|
+
elem_type_info = analyze_type_info(type_info.elem_type)
|
345
|
+
encoded_type["element_type"] = _encode_type(elem_type_info)
|
346
346
|
encoded_type["dimension"] = type_info.vector_info.dim
|
347
347
|
|
348
348
|
elif type_info.kind in TABLE_TYPES:
|
@@ -1,12 +1,12 @@
|
|
1
|
-
cocoindex-0.1.
|
2
|
-
cocoindex-0.1.
|
3
|
-
cocoindex-0.1.
|
4
|
-
cocoindex-0.1.
|
5
|
-
cocoindex/__init__.py,sha256=
|
6
|
-
cocoindex/_engine.cp312-win_amd64.pyd,sha256=
|
1
|
+
cocoindex-0.1.51.dist-info/METADATA,sha256=VWHNukHF17O5re8ldifAS_BV1WTtfh4Iv8HDP_6ADIo,10040
|
2
|
+
cocoindex-0.1.51.dist-info/WHEEL,sha256=2Rq0eWWH7u9Ffm_ZQEcE2_DVE8if9XSfMophnE-xWmc,96
|
3
|
+
cocoindex-0.1.51.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
|
4
|
+
cocoindex-0.1.51.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
5
|
+
cocoindex/__init__.py,sha256=1-ymMFyNmEMpYyWfpOTsh84C4pYnNVeVHfrzusaINdk,1766
|
6
|
+
cocoindex/_engine.cp312-win_amd64.pyd,sha256=P0AnfNs1uowQRJAOB0qDEfc3MzXuLPcVC7VI8syrOvM,61389312
|
7
7
|
cocoindex/auth_registry.py,sha256=LojDKoX0ccO-G3bboFMlAti50_t5GK9BS0ouPJZfyUs,745
|
8
|
-
cocoindex/cli.py,sha256=
|
9
|
-
cocoindex/convert.py,sha256=
|
8
|
+
cocoindex/cli.py,sha256=Sp_Hq3hyLU1JtQNHwlKEhReoGqNjJoAWhIGt_Q9kZDk,18800
|
9
|
+
cocoindex/convert.py,sha256=3OInFkmwi8RxdyAJsCLEdMa8tmmnX0Q1I0JFsInXDLo,9037
|
10
10
|
cocoindex/flow.py,sha256=ElTNrp9cxUZiKSvLMRwjU9rNQUn2d9zxryJzCxCFx4I,30985
|
11
11
|
cocoindex/functions.py,sha256=3l7POrvuk5DVIwGUgCODAi-JNFJ1_WLTOg6Yn-uZ0IE,2471
|
12
12
|
cocoindex/index.py,sha256=GrqTm1rLwICQ8hadtNvJAxVg7GWMvtMmFcbiNtNzmP0,569
|
@@ -15,13 +15,14 @@ cocoindex/llm.py,sha256=sI46pXpTmOLOBOBpqCB2pnwDHz4PdVyEPBKZuIxObpU,372
|
|
15
15
|
cocoindex/op.py,sha256=qSf2-zGd77YVXDC8UWUyAtDIHklNrRaFn1ZvLK5T64g,12148
|
16
16
|
cocoindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
17
|
cocoindex/runtime.py,sha256=saKEZntVwUVQNASRhiO9bHRVIFmQccemq2f9mo4mo1A,1090
|
18
|
-
cocoindex/setting.py,sha256=
|
18
|
+
cocoindex/setting.py,sha256=dRNdX-rPBn321zGx6GGoSMggS4F2879A6EBLOUbX8R4,3717
|
19
19
|
cocoindex/setup.py,sha256=nqJAEGQH-5yTulEy3aCAa9khbuiaqD81ZZUdeM3K_lo,799
|
20
20
|
cocoindex/sources.py,sha256=4hxsntuyClp_jKH4oZbx3iE3UM4P2bZTpWy28dqdyFY,1375
|
21
21
|
cocoindex/storages.py,sha256=WrfpGcOImFXH0DTEdBPRmL4GwyO62lfANMd6rTejxuQ,2939
|
22
22
|
cocoindex/tests/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
23
|
-
cocoindex/tests/test_convert.py,sha256=
|
24
|
-
cocoindex/tests/
|
25
|
-
cocoindex/
|
23
|
+
cocoindex/tests/test_convert.py,sha256=tIOFqF2LzHvW7v5Ny-JWAUhzvpskDOedHKmOTrQpEUw,29774
|
24
|
+
cocoindex/tests/test_optional_database.py,sha256=dnzmTgaJf37D3q8fQsjP5UDER6FYETaUokDnFBMLtIk,8755
|
25
|
+
cocoindex/tests/test_typing.py,sha256=9Fc_GALPinF9PdVlaO1_fFLi12dc7cNaV8XJma0f-2s,12818
|
26
|
+
cocoindex/typing.py,sha256=geA2nOq_frf9NGB_XpNDOHTviAitRbgYH5OWQ59VOgQ,12780
|
26
27
|
cocoindex/utils.py,sha256=RLyawj_M4ZDL-gwJ16e5p2AcFYIL50DlMkfZyKaNB2o,520
|
27
|
-
cocoindex-0.1.
|
28
|
+
cocoindex-0.1.51.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|