pixeltable 0.1.0__py3-none-any.whl → 0.2.4__py3-none-any.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.
Potentially problematic release.
This version of pixeltable might be problematic. Click here for more details.
- pixeltable/__init__.py +34 -6
- pixeltable/catalog/__init__.py +13 -0
- pixeltable/catalog/catalog.py +159 -0
- pixeltable/catalog/column.py +200 -0
- pixeltable/catalog/dir.py +32 -0
- pixeltable/catalog/globals.py +33 -0
- pixeltable/catalog/insertable_table.py +191 -0
- pixeltable/catalog/named_function.py +36 -0
- pixeltable/catalog/path.py +58 -0
- pixeltable/catalog/path_dict.py +139 -0
- pixeltable/catalog/schema_object.py +39 -0
- pixeltable/catalog/table.py +581 -0
- pixeltable/catalog/table_version.py +749 -0
- pixeltable/catalog/table_version_path.py +133 -0
- pixeltable/catalog/view.py +203 -0
- pixeltable/client.py +590 -30
- pixeltable/dataframe.py +540 -349
- pixeltable/env.py +359 -45
- pixeltable/exceptions.py +12 -21
- pixeltable/exec/__init__.py +9 -0
- pixeltable/exec/aggregation_node.py +78 -0
- pixeltable/exec/cache_prefetch_node.py +116 -0
- pixeltable/exec/component_iteration_node.py +79 -0
- pixeltable/exec/data_row_batch.py +95 -0
- pixeltable/exec/exec_context.py +22 -0
- pixeltable/exec/exec_node.py +61 -0
- pixeltable/exec/expr_eval_node.py +217 -0
- pixeltable/exec/in_memory_data_node.py +69 -0
- pixeltable/exec/media_validation_node.py +43 -0
- pixeltable/exec/sql_scan_node.py +225 -0
- pixeltable/exprs/__init__.py +24 -0
- pixeltable/exprs/arithmetic_expr.py +102 -0
- pixeltable/exprs/array_slice.py +71 -0
- pixeltable/exprs/column_property_ref.py +77 -0
- pixeltable/exprs/column_ref.py +105 -0
- pixeltable/exprs/comparison.py +77 -0
- pixeltable/exprs/compound_predicate.py +98 -0
- pixeltable/exprs/data_row.py +195 -0
- pixeltable/exprs/expr.py +586 -0
- pixeltable/exprs/expr_set.py +39 -0
- pixeltable/exprs/function_call.py +380 -0
- pixeltable/exprs/globals.py +69 -0
- pixeltable/exprs/image_member_access.py +115 -0
- pixeltable/exprs/image_similarity_predicate.py +58 -0
- pixeltable/exprs/inline_array.py +107 -0
- pixeltable/exprs/inline_dict.py +101 -0
- pixeltable/exprs/is_null.py +38 -0
- pixeltable/exprs/json_mapper.py +121 -0
- pixeltable/exprs/json_path.py +159 -0
- pixeltable/exprs/literal.py +54 -0
- pixeltable/exprs/object_ref.py +41 -0
- pixeltable/exprs/predicate.py +44 -0
- pixeltable/exprs/row_builder.py +355 -0
- pixeltable/exprs/rowid_ref.py +94 -0
- pixeltable/exprs/type_cast.py +53 -0
- pixeltable/exprs/variable.py +45 -0
- pixeltable/func/__init__.py +9 -0
- pixeltable/func/aggregate_function.py +194 -0
- pixeltable/func/batched_function.py +53 -0
- pixeltable/func/callable_function.py +69 -0
- pixeltable/func/expr_template_function.py +82 -0
- pixeltable/func/function.py +110 -0
- pixeltable/func/function_registry.py +227 -0
- pixeltable/func/globals.py +36 -0
- pixeltable/func/nos_function.py +202 -0
- pixeltable/func/signature.py +166 -0
- pixeltable/func/udf.py +163 -0
- pixeltable/functions/__init__.py +52 -103
- pixeltable/functions/eval.py +216 -0
- pixeltable/functions/fireworks.py +34 -0
- pixeltable/functions/huggingface.py +120 -0
- pixeltable/functions/image.py +16 -0
- pixeltable/functions/openai.py +256 -0
- pixeltable/functions/pil/image.py +148 -7
- pixeltable/functions/string.py +13 -0
- pixeltable/functions/together.py +122 -0
- pixeltable/functions/util.py +41 -0
- pixeltable/functions/video.py +62 -0
- pixeltable/iterators/__init__.py +3 -0
- pixeltable/iterators/base.py +48 -0
- pixeltable/iterators/document.py +311 -0
- pixeltable/iterators/video.py +89 -0
- pixeltable/metadata/__init__.py +54 -0
- pixeltable/metadata/converters/convert_10.py +18 -0
- pixeltable/metadata/schema.py +211 -0
- pixeltable/plan.py +656 -0
- pixeltable/store.py +418 -182
- pixeltable/tests/conftest.py +146 -88
- pixeltable/tests/functions/test_fireworks.py +42 -0
- pixeltable/tests/functions/test_functions.py +60 -0
- pixeltable/tests/functions/test_huggingface.py +158 -0
- pixeltable/tests/functions/test_openai.py +152 -0
- pixeltable/tests/functions/test_together.py +111 -0
- pixeltable/tests/test_audio.py +65 -0
- pixeltable/tests/test_catalog.py +27 -0
- pixeltable/tests/test_client.py +14 -14
- pixeltable/tests/test_component_view.py +370 -0
- pixeltable/tests/test_dataframe.py +439 -0
- pixeltable/tests/test_dirs.py +78 -62
- pixeltable/tests/test_document.py +120 -0
- pixeltable/tests/test_exprs.py +592 -135
- pixeltable/tests/test_function.py +297 -67
- pixeltable/tests/test_migration.py +43 -0
- pixeltable/tests/test_nos.py +54 -0
- pixeltable/tests/test_snapshot.py +208 -0
- pixeltable/tests/test_table.py +1195 -263
- pixeltable/tests/test_transactional_directory.py +42 -0
- pixeltable/tests/test_types.py +5 -11
- pixeltable/tests/test_video.py +151 -34
- pixeltable/tests/test_view.py +530 -0
- pixeltable/tests/utils.py +320 -45
- pixeltable/tool/create_test_db_dump.py +149 -0
- pixeltable/tool/create_test_video.py +81 -0
- pixeltable/type_system.py +445 -124
- pixeltable/utils/__init__.py +17 -46
- pixeltable/utils/arrow.py +98 -0
- pixeltable/utils/clip.py +12 -15
- pixeltable/utils/coco.py +136 -0
- pixeltable/utils/documents.py +39 -0
- pixeltable/utils/filecache.py +195 -0
- pixeltable/utils/help.py +11 -0
- pixeltable/utils/hf_datasets.py +157 -0
- pixeltable/utils/media_store.py +76 -0
- pixeltable/utils/parquet.py +167 -0
- pixeltable/utils/pytorch.py +91 -0
- pixeltable/utils/s3.py +13 -0
- pixeltable/utils/sql.py +17 -0
- pixeltable/utils/transactional_directory.py +35 -0
- pixeltable-0.2.4.dist-info/LICENSE +18 -0
- pixeltable-0.2.4.dist-info/METADATA +127 -0
- pixeltable-0.2.4.dist-info/RECORD +132 -0
- {pixeltable-0.1.0.dist-info → pixeltable-0.2.4.dist-info}/WHEEL +1 -1
- pixeltable/catalog.py +0 -1421
- pixeltable/exprs.py +0 -1745
- pixeltable/function.py +0 -269
- pixeltable/functions/clip.py +0 -10
- pixeltable/functions/pil/__init__.py +0 -23
- pixeltable/functions/tf.py +0 -21
- pixeltable/index.py +0 -57
- pixeltable/tests/test_dict.py +0 -24
- pixeltable/tests/test_functions.py +0 -11
- pixeltable/tests/test_tf.py +0 -69
- pixeltable/tf.py +0 -33
- pixeltable/utils/tf.py +0 -33
- pixeltable/utils/video.py +0 -32
- pixeltable-0.1.0.dist-info/METADATA +0 -34
- pixeltable-0.1.0.dist-info/RECORD +0 -36
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
import json
|
|
3
|
+
import re
|
|
4
|
+
from typing import Optional, Set, List
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
import pixeltable as pxt
|
|
9
|
+
from pixeltable.iterators.document import DocumentSplitter
|
|
10
|
+
from pixeltable.tests.utils import get_documents, get_video_files, get_audio_files, get_image_files
|
|
11
|
+
from pixeltable.tests.utils import skip_test_if_not_installed
|
|
12
|
+
from pixeltable.type_system import DocumentType
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestDocument:
|
|
16
|
+
def valid_doc_paths(self) -> List[str]:
|
|
17
|
+
return get_documents()
|
|
18
|
+
|
|
19
|
+
def invalid_doc_paths(self) -> List[str]:
|
|
20
|
+
return [get_video_files()[0], get_audio_files()[0], get_image_files()[0]]
|
|
21
|
+
|
|
22
|
+
def test_insert(self, test_client: pxt.Client) -> None:
|
|
23
|
+
file_paths = self.valid_doc_paths()
|
|
24
|
+
cl = test_client
|
|
25
|
+
doc_t = cl.create_table('docs', {'doc': DocumentType()})
|
|
26
|
+
status = doc_t.insert({'doc': p} for p in file_paths)
|
|
27
|
+
assert status.num_rows == len(file_paths)
|
|
28
|
+
assert status.num_excs == 0
|
|
29
|
+
stored_paths = doc_t.select(output=doc_t.doc.localpath).collect()['output']
|
|
30
|
+
assert set(stored_paths) == set(file_paths)
|
|
31
|
+
|
|
32
|
+
file_paths = self.invalid_doc_paths()
|
|
33
|
+
status = doc_t.insert(({'doc': p} for p in file_paths), fail_on_exception=False)
|
|
34
|
+
assert status.num_rows == len(file_paths)
|
|
35
|
+
assert status.num_excs == len(file_paths)
|
|
36
|
+
|
|
37
|
+
def test_doc_splitter(self, test_client: pxt.Client) -> None:
|
|
38
|
+
skip_test_if_not_installed('tiktoken')
|
|
39
|
+
file_paths = self.valid_doc_paths()
|
|
40
|
+
cl = test_client
|
|
41
|
+
doc_t = cl.create_table('docs', {'doc': DocumentType()})
|
|
42
|
+
status = doc_t.insert({'doc': p} for p in file_paths)
|
|
43
|
+
assert status.num_excs == 0
|
|
44
|
+
|
|
45
|
+
def normalize(s: str) -> str:
|
|
46
|
+
# remove whitespace
|
|
47
|
+
res = re.sub(r'\s+', '', s)
|
|
48
|
+
# remove non-ascii
|
|
49
|
+
res = res.encode('ascii', 'ignore').decode()
|
|
50
|
+
return res
|
|
51
|
+
|
|
52
|
+
# run all combinations of (heading, paragraph, sentence) x (token_limit, char_limit, None)
|
|
53
|
+
# and make sure they extract the same text in aggregate
|
|
54
|
+
all_text_reference: Optional[str] = None # all text as a single string; normalized
|
|
55
|
+
headings_reference: Set[str] = {} # headings metadata as a json-serialized string
|
|
56
|
+
for sep1 in ['heading', 'paragraph', 'sentence']:
|
|
57
|
+
for sep2 in [None, 'token_limit', 'char_limit']:
|
|
58
|
+
chunk_limits = [10, 20, 100] if sep2 is not None else [None]
|
|
59
|
+
for limit in chunk_limits:
|
|
60
|
+
iterator_args = {
|
|
61
|
+
'document': doc_t.doc,
|
|
62
|
+
'separators': sep1 + (',' + sep2 if sep2 is not None else ''),
|
|
63
|
+
'metadata': 'title,headings,sourceline'
|
|
64
|
+
}
|
|
65
|
+
if sep2 is not None:
|
|
66
|
+
iterator_args['limit'] = limit
|
|
67
|
+
iterator_args['overlap'] = 0
|
|
68
|
+
chunks_t = cl.create_view(
|
|
69
|
+
f'chunks', doc_t, iterator_class=DocumentSplitter, iterator_args=iterator_args)
|
|
70
|
+
res = list(chunks_t.order_by(chunks_t.doc, chunks_t.pos).collect())
|
|
71
|
+
|
|
72
|
+
if all_text_reference is None:
|
|
73
|
+
all_text_reference = normalize(''.join([r['text'] for r in res]))
|
|
74
|
+
headings_reference = set(json.dumps(r['headings']) for r in res)
|
|
75
|
+
else:
|
|
76
|
+
all_text = normalize(''.join([r['text'] for r in res]))
|
|
77
|
+
headings = set(json.dumps(r['headings']) for r in res)
|
|
78
|
+
|
|
79
|
+
# for debugging
|
|
80
|
+
first_diff_index = next(
|
|
81
|
+
(i for i, (c1, c2) in enumerate(zip(all_text, all_text_reference)) if c1 != c2),
|
|
82
|
+
len(all_text) if len(all_text) != len(all_text_reference) else None)
|
|
83
|
+
if first_diff_index is not None:
|
|
84
|
+
a = all_text[max(0, first_diff_index - 10):first_diff_index + 10]
|
|
85
|
+
b = all_text_reference[max(0, first_diff_index - 10):first_diff_index + 10]
|
|
86
|
+
|
|
87
|
+
assert all_text == all_text_reference, f'{sep1}, {sep2}, {limit}'
|
|
88
|
+
assert headings == headings_reference, f'{sep1}, {sep2}, {limit}'
|
|
89
|
+
# TODO: verify chunk limit
|
|
90
|
+
cl.drop_table('chunks')
|
|
91
|
+
|
|
92
|
+
def test_doc_splitter_headings(self, test_client: pxt.Client) -> None:
|
|
93
|
+
skip_test_if_not_installed('spacy')
|
|
94
|
+
file_paths = self.valid_doc_paths()
|
|
95
|
+
cl = test_client
|
|
96
|
+
doc_t = cl.create_table('docs', {'doc': DocumentType()})
|
|
97
|
+
status = doc_t.insert({'doc': p} for p in file_paths)
|
|
98
|
+
assert status.num_excs == 0
|
|
99
|
+
|
|
100
|
+
# verify that only the requested metadata is present in the view
|
|
101
|
+
md_elements = ['title', 'headings', 'sourceline']
|
|
102
|
+
md_tuples = list(itertools.chain.from_iterable(itertools.combinations(md_elements, i) for i in range(len(md_elements) + 1)))
|
|
103
|
+
_ = [','.join(t) for t in md_tuples]
|
|
104
|
+
for md_str in [','.join(t) for t in md_tuples]:
|
|
105
|
+
iterator_args = {
|
|
106
|
+
'document': doc_t.doc,
|
|
107
|
+
'separators': 'sentence',
|
|
108
|
+
'metadata': md_str
|
|
109
|
+
}
|
|
110
|
+
chunks_t = cl.create_view(
|
|
111
|
+
f'chunks', doc_t, iterator_class=DocumentSplitter, iterator_args=iterator_args)
|
|
112
|
+
res = chunks_t.order_by(chunks_t.doc, chunks_t.pos).collect()
|
|
113
|
+
requested_md_elements = set(md_str.split(','))
|
|
114
|
+
for md_element in md_elements:
|
|
115
|
+
if md_element in requested_md_elements:
|
|
116
|
+
_ = res[md_element]
|
|
117
|
+
else:
|
|
118
|
+
with pytest.raises(pxt.Error):
|
|
119
|
+
_ = res[md_element]
|
|
120
|
+
cl.drop_table('chunks')
|