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.

Files changed (147) hide show
  1. pixeltable/__init__.py +34 -6
  2. pixeltable/catalog/__init__.py +13 -0
  3. pixeltable/catalog/catalog.py +159 -0
  4. pixeltable/catalog/column.py +200 -0
  5. pixeltable/catalog/dir.py +32 -0
  6. pixeltable/catalog/globals.py +33 -0
  7. pixeltable/catalog/insertable_table.py +191 -0
  8. pixeltable/catalog/named_function.py +36 -0
  9. pixeltable/catalog/path.py +58 -0
  10. pixeltable/catalog/path_dict.py +139 -0
  11. pixeltable/catalog/schema_object.py +39 -0
  12. pixeltable/catalog/table.py +581 -0
  13. pixeltable/catalog/table_version.py +749 -0
  14. pixeltable/catalog/table_version_path.py +133 -0
  15. pixeltable/catalog/view.py +203 -0
  16. pixeltable/client.py +590 -30
  17. pixeltable/dataframe.py +540 -349
  18. pixeltable/env.py +359 -45
  19. pixeltable/exceptions.py +12 -21
  20. pixeltable/exec/__init__.py +9 -0
  21. pixeltable/exec/aggregation_node.py +78 -0
  22. pixeltable/exec/cache_prefetch_node.py +116 -0
  23. pixeltable/exec/component_iteration_node.py +79 -0
  24. pixeltable/exec/data_row_batch.py +95 -0
  25. pixeltable/exec/exec_context.py +22 -0
  26. pixeltable/exec/exec_node.py +61 -0
  27. pixeltable/exec/expr_eval_node.py +217 -0
  28. pixeltable/exec/in_memory_data_node.py +69 -0
  29. pixeltable/exec/media_validation_node.py +43 -0
  30. pixeltable/exec/sql_scan_node.py +225 -0
  31. pixeltable/exprs/__init__.py +24 -0
  32. pixeltable/exprs/arithmetic_expr.py +102 -0
  33. pixeltable/exprs/array_slice.py +71 -0
  34. pixeltable/exprs/column_property_ref.py +77 -0
  35. pixeltable/exprs/column_ref.py +105 -0
  36. pixeltable/exprs/comparison.py +77 -0
  37. pixeltable/exprs/compound_predicate.py +98 -0
  38. pixeltable/exprs/data_row.py +195 -0
  39. pixeltable/exprs/expr.py +586 -0
  40. pixeltable/exprs/expr_set.py +39 -0
  41. pixeltable/exprs/function_call.py +380 -0
  42. pixeltable/exprs/globals.py +69 -0
  43. pixeltable/exprs/image_member_access.py +115 -0
  44. pixeltable/exprs/image_similarity_predicate.py +58 -0
  45. pixeltable/exprs/inline_array.py +107 -0
  46. pixeltable/exprs/inline_dict.py +101 -0
  47. pixeltable/exprs/is_null.py +38 -0
  48. pixeltable/exprs/json_mapper.py +121 -0
  49. pixeltable/exprs/json_path.py +159 -0
  50. pixeltable/exprs/literal.py +54 -0
  51. pixeltable/exprs/object_ref.py +41 -0
  52. pixeltable/exprs/predicate.py +44 -0
  53. pixeltable/exprs/row_builder.py +355 -0
  54. pixeltable/exprs/rowid_ref.py +94 -0
  55. pixeltable/exprs/type_cast.py +53 -0
  56. pixeltable/exprs/variable.py +45 -0
  57. pixeltable/func/__init__.py +9 -0
  58. pixeltable/func/aggregate_function.py +194 -0
  59. pixeltable/func/batched_function.py +53 -0
  60. pixeltable/func/callable_function.py +69 -0
  61. pixeltable/func/expr_template_function.py +82 -0
  62. pixeltable/func/function.py +110 -0
  63. pixeltable/func/function_registry.py +227 -0
  64. pixeltable/func/globals.py +36 -0
  65. pixeltable/func/nos_function.py +202 -0
  66. pixeltable/func/signature.py +166 -0
  67. pixeltable/func/udf.py +163 -0
  68. pixeltable/functions/__init__.py +52 -103
  69. pixeltable/functions/eval.py +216 -0
  70. pixeltable/functions/fireworks.py +34 -0
  71. pixeltable/functions/huggingface.py +120 -0
  72. pixeltable/functions/image.py +16 -0
  73. pixeltable/functions/openai.py +256 -0
  74. pixeltable/functions/pil/image.py +148 -7
  75. pixeltable/functions/string.py +13 -0
  76. pixeltable/functions/together.py +122 -0
  77. pixeltable/functions/util.py +41 -0
  78. pixeltable/functions/video.py +62 -0
  79. pixeltable/iterators/__init__.py +3 -0
  80. pixeltable/iterators/base.py +48 -0
  81. pixeltable/iterators/document.py +311 -0
  82. pixeltable/iterators/video.py +89 -0
  83. pixeltable/metadata/__init__.py +54 -0
  84. pixeltable/metadata/converters/convert_10.py +18 -0
  85. pixeltable/metadata/schema.py +211 -0
  86. pixeltable/plan.py +656 -0
  87. pixeltable/store.py +418 -182
  88. pixeltable/tests/conftest.py +146 -88
  89. pixeltable/tests/functions/test_fireworks.py +42 -0
  90. pixeltable/tests/functions/test_functions.py +60 -0
  91. pixeltable/tests/functions/test_huggingface.py +158 -0
  92. pixeltable/tests/functions/test_openai.py +152 -0
  93. pixeltable/tests/functions/test_together.py +111 -0
  94. pixeltable/tests/test_audio.py +65 -0
  95. pixeltable/tests/test_catalog.py +27 -0
  96. pixeltable/tests/test_client.py +14 -14
  97. pixeltable/tests/test_component_view.py +370 -0
  98. pixeltable/tests/test_dataframe.py +439 -0
  99. pixeltable/tests/test_dirs.py +78 -62
  100. pixeltable/tests/test_document.py +120 -0
  101. pixeltable/tests/test_exprs.py +592 -135
  102. pixeltable/tests/test_function.py +297 -67
  103. pixeltable/tests/test_migration.py +43 -0
  104. pixeltable/tests/test_nos.py +54 -0
  105. pixeltable/tests/test_snapshot.py +208 -0
  106. pixeltable/tests/test_table.py +1195 -263
  107. pixeltable/tests/test_transactional_directory.py +42 -0
  108. pixeltable/tests/test_types.py +5 -11
  109. pixeltable/tests/test_video.py +151 -34
  110. pixeltable/tests/test_view.py +530 -0
  111. pixeltable/tests/utils.py +320 -45
  112. pixeltable/tool/create_test_db_dump.py +149 -0
  113. pixeltable/tool/create_test_video.py +81 -0
  114. pixeltable/type_system.py +445 -124
  115. pixeltable/utils/__init__.py +17 -46
  116. pixeltable/utils/arrow.py +98 -0
  117. pixeltable/utils/clip.py +12 -15
  118. pixeltable/utils/coco.py +136 -0
  119. pixeltable/utils/documents.py +39 -0
  120. pixeltable/utils/filecache.py +195 -0
  121. pixeltable/utils/help.py +11 -0
  122. pixeltable/utils/hf_datasets.py +157 -0
  123. pixeltable/utils/media_store.py +76 -0
  124. pixeltable/utils/parquet.py +167 -0
  125. pixeltable/utils/pytorch.py +91 -0
  126. pixeltable/utils/s3.py +13 -0
  127. pixeltable/utils/sql.py +17 -0
  128. pixeltable/utils/transactional_directory.py +35 -0
  129. pixeltable-0.2.4.dist-info/LICENSE +18 -0
  130. pixeltable-0.2.4.dist-info/METADATA +127 -0
  131. pixeltable-0.2.4.dist-info/RECORD +132 -0
  132. {pixeltable-0.1.0.dist-info → pixeltable-0.2.4.dist-info}/WHEEL +1 -1
  133. pixeltable/catalog.py +0 -1421
  134. pixeltable/exprs.py +0 -1745
  135. pixeltable/function.py +0 -269
  136. pixeltable/functions/clip.py +0 -10
  137. pixeltable/functions/pil/__init__.py +0 -23
  138. pixeltable/functions/tf.py +0 -21
  139. pixeltable/index.py +0 -57
  140. pixeltable/tests/test_dict.py +0 -24
  141. pixeltable/tests/test_functions.py +0 -11
  142. pixeltable/tests/test_tf.py +0 -69
  143. pixeltable/tf.py +0 -33
  144. pixeltable/utils/tf.py +0 -33
  145. pixeltable/utils/video.py +0 -32
  146. pixeltable-0.1.0.dist-info/METADATA +0 -34
  147. 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')