pixeltable 0.1.1__py3-none-any.whl → 0.2.0__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 (139) 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 +520 -30
  17. pixeltable/dataframe.py +540 -349
  18. pixeltable/env.py +373 -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 +113 -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 +187 -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 +61 -0
  71. pixeltable/functions/huggingface.py +120 -0
  72. pixeltable/functions/image.py +16 -0
  73. pixeltable/functions/openai.py +88 -0
  74. pixeltable/functions/pil/image.py +148 -7
  75. pixeltable/functions/string.py +13 -0
  76. pixeltable/functions/together.py +27 -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 +413 -182
  88. pixeltable/tests/conftest.py +143 -87
  89. pixeltable/tests/test_audio.py +65 -0
  90. pixeltable/tests/test_catalog.py +27 -0
  91. pixeltable/tests/test_client.py +14 -14
  92. pixeltable/tests/test_component_view.py +372 -0
  93. pixeltable/tests/test_dataframe.py +433 -0
  94. pixeltable/tests/test_dirs.py +78 -62
  95. pixeltable/tests/test_document.py +117 -0
  96. pixeltable/tests/test_exprs.py +591 -135
  97. pixeltable/tests/test_function.py +297 -67
  98. pixeltable/tests/test_functions.py +283 -1
  99. pixeltable/tests/test_migration.py +43 -0
  100. pixeltable/tests/test_nos.py +54 -0
  101. pixeltable/tests/test_snapshot.py +208 -0
  102. pixeltable/tests/test_table.py +1085 -262
  103. pixeltable/tests/test_transactional_directory.py +42 -0
  104. pixeltable/tests/test_types.py +5 -11
  105. pixeltable/tests/test_video.py +149 -34
  106. pixeltable/tests/test_view.py +530 -0
  107. pixeltable/tests/utils.py +186 -45
  108. pixeltable/tool/create_test_db_dump.py +149 -0
  109. pixeltable/type_system.py +490 -126
  110. pixeltable/utils/__init__.py +17 -46
  111. pixeltable/utils/clip.py +12 -15
  112. pixeltable/utils/coco.py +136 -0
  113. pixeltable/utils/documents.py +39 -0
  114. pixeltable/utils/filecache.py +195 -0
  115. pixeltable/utils/help.py +11 -0
  116. pixeltable/utils/media_store.py +76 -0
  117. pixeltable/utils/parquet.py +126 -0
  118. pixeltable/utils/pytorch.py +172 -0
  119. pixeltable/utils/s3.py +13 -0
  120. pixeltable/utils/sql.py +17 -0
  121. pixeltable/utils/transactional_directory.py +35 -0
  122. pixeltable-0.2.0.dist-info/LICENSE +18 -0
  123. pixeltable-0.2.0.dist-info/METADATA +117 -0
  124. pixeltable-0.2.0.dist-info/RECORD +125 -0
  125. {pixeltable-0.1.1.dist-info → pixeltable-0.2.0.dist-info}/WHEEL +1 -1
  126. pixeltable/catalog.py +0 -1421
  127. pixeltable/exprs.py +0 -1745
  128. pixeltable/function.py +0 -269
  129. pixeltable/functions/clip.py +0 -10
  130. pixeltable/functions/pil/__init__.py +0 -23
  131. pixeltable/functions/tf.py +0 -21
  132. pixeltable/index.py +0 -57
  133. pixeltable/tests/test_dict.py +0 -24
  134. pixeltable/tests/test_tf.py +0 -69
  135. pixeltable/tf.py +0 -33
  136. pixeltable/utils/tf.py +0 -33
  137. pixeltable/utils/video.py +0 -32
  138. pixeltable-0.1.1.dist-info/METADATA +0 -31
  139. pixeltable-0.1.1.dist-info/RECORD +0 -36
@@ -0,0 +1,117 @@
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.type_system import DocumentType
12
+
13
+
14
+ class TestDocument:
15
+ def valid_doc_paths(self) -> List[str]:
16
+ return get_documents()
17
+
18
+ def invalid_doc_paths(self) -> List[str]:
19
+ return [get_video_files()[0], get_audio_files()[0], get_image_files()[0]]
20
+
21
+ def test_insert(self, test_client: pxt.Client) -> None:
22
+ file_paths = self.valid_doc_paths()
23
+ cl = test_client
24
+ doc_t = cl.create_table('docs', {'doc': DocumentType()})
25
+ status = doc_t.insert({'doc': p} for p in file_paths)
26
+ assert status.num_rows == len(file_paths)
27
+ assert status.num_excs == 0
28
+ stored_paths = doc_t.select(output=doc_t.doc.localpath).collect()['output']
29
+ assert set(stored_paths) == set(file_paths)
30
+
31
+ file_paths = self.invalid_doc_paths()
32
+ status = doc_t.insert(({'doc': p} for p in file_paths), fail_on_exception=False)
33
+ assert status.num_rows == len(file_paths)
34
+ assert status.num_excs == len(file_paths)
35
+
36
+ def test_doc_splitter(self, test_client: pxt.Client) -> None:
37
+ file_paths = self.valid_doc_paths()
38
+ cl = test_client
39
+ doc_t = cl.create_table('docs', {'doc': DocumentType()})
40
+ status = doc_t.insert({'doc': p} for p in file_paths)
41
+ assert status.num_excs == 0
42
+
43
+ def normalize(s: str) -> str:
44
+ # remove whitespace
45
+ res = re.sub(r'\s+', '', s)
46
+ # remove non-ascii
47
+ res = res.encode('ascii', 'ignore').decode()
48
+ return res
49
+
50
+ # run all combinations of (heading, paragraph, sentence) x (token_limit, char_limit, None)
51
+ # and make sure they extract the same text in aggregate
52
+ all_text_reference: Optional[str] = None # all text as a single string; normalized
53
+ headings_reference: Set[str] = {} # headings metadata as a json-serialized string
54
+ for sep1 in ['heading', 'paragraph', 'sentence']:
55
+ for sep2 in [None, 'token_limit', 'char_limit']:
56
+ chunk_limits = [10, 20, 100] if sep2 is not None else [None]
57
+ for limit in chunk_limits:
58
+ iterator_args = {
59
+ 'document': doc_t.doc,
60
+ 'separators': sep1 + (',' + sep2 if sep2 is not None else ''),
61
+ 'metadata': 'title,headings,sourceline'
62
+ }
63
+ if sep2 is not None:
64
+ iterator_args['limit'] = limit
65
+ iterator_args['overlap'] = 0
66
+ chunks_t = cl.create_view(
67
+ f'chunks', doc_t, iterator_class=DocumentSplitter, iterator_args=iterator_args)
68
+ res = list(chunks_t.order_by(chunks_t.doc, chunks_t.pos).collect())
69
+
70
+ if all_text_reference is None:
71
+ all_text_reference = normalize(''.join([r['text'] for r in res]))
72
+ headings_reference = set(json.dumps(r['headings']) for r in res)
73
+ else:
74
+ all_text = normalize(''.join([r['text'] for r in res]))
75
+ headings = set(json.dumps(r['headings']) for r in res)
76
+
77
+ # for debugging
78
+ first_diff_index = next(
79
+ (i for i, (c1, c2) in enumerate(zip(all_text, all_text_reference)) if c1 != c2),
80
+ len(all_text) if len(all_text) != len(all_text_reference) else None)
81
+ if first_diff_index is not None:
82
+ a = all_text[max(0, first_diff_index - 10):first_diff_index + 10]
83
+ b = all_text_reference[max(0, first_diff_index - 10):first_diff_index + 10]
84
+
85
+ assert all_text == all_text_reference, f'{sep1}, {sep2}, {limit}'
86
+ assert headings == headings_reference, f'{sep1}, {sep2}, {limit}'
87
+ # TODO: verify chunk limit
88
+ cl.drop_table('chunks')
89
+
90
+ def test_doc_splitter_headings(self, test_client: pxt.Client) -> None:
91
+ file_paths = self.valid_doc_paths()
92
+ cl = test_client
93
+ doc_t = cl.create_table('docs', {'doc': DocumentType()})
94
+ status = doc_t.insert({'doc': p} for p in file_paths)
95
+ assert status.num_excs == 0
96
+
97
+ # verify that only the requested metadata is present in the view
98
+ md_elements = ['title', 'headings', 'sourceline']
99
+ md_tuples = list(itertools.chain.from_iterable(itertools.combinations(md_elements, i) for i in range(len(md_elements) + 1)))
100
+ _ = [','.join(t) for t in md_tuples]
101
+ for md_str in [','.join(t) for t in md_tuples]:
102
+ iterator_args = {
103
+ 'document': doc_t.doc,
104
+ 'separators': 'sentence',
105
+ 'metadata': md_str
106
+ }
107
+ chunks_t = cl.create_view(
108
+ f'chunks', doc_t, iterator_class=DocumentSplitter, iterator_args=iterator_args)
109
+ res = chunks_t.order_by(chunks_t.doc, chunks_t.pos).collect()
110
+ requested_md_elements = set(md_str.split(','))
111
+ for md_element in md_elements:
112
+ if md_element in requested_md_elements:
113
+ _ = res[md_element]
114
+ else:
115
+ with pytest.raises(pxt.Error):
116
+ _ = res[md_element]
117
+ cl.drop_table('chunks')