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,152 @@
1
+ import pytest
2
+
3
+ import pixeltable as pxt
4
+ import pixeltable.exceptions as excs
5
+ from pixeltable.tests.utils import SAMPLE_IMAGE_URL, skip_test_if_not_installed, validate_update_status
6
+ from pixeltable.type_system import StringType, ImageType
7
+
8
+
9
+ class TestOpenai:
10
+
11
+ def test_audio(self, test_client: pxt.Client) -> None:
12
+ skip_test_if_not_installed('openai')
13
+ TestOpenai.skip_test_if_no_openai_client()
14
+ cl = test_client
15
+ t = cl.create_table('test_tbl', {'input': StringType()})
16
+ from pixeltable.functions.openai import speech, transcriptions, translations
17
+ t.add_column(speech=speech(t.input, model='tts-1', voice='onyx'))
18
+ t.add_column(speech_2=speech(t.input, model='tts-1', voice='onyx', response_format='flac', speed=1.05))
19
+ t.add_column(transcription=transcriptions(t.speech, model='whisper-1'))
20
+ t.add_column(transcription_2=transcriptions(
21
+ t.speech, model='whisper-1', language='en', prompt='Transcribe the contents of this recording.'
22
+ ))
23
+ t.add_column(translation=translations(t.speech, model='whisper-1'))
24
+ t.add_column(translation_2=translations(
25
+ t.speech, model='whisper-1', prompt='Translate the recording from Spanish into English.', temperature=0.7
26
+ ))
27
+ validate_update_status(t.insert([
28
+ {'input': 'I am a banana.'},
29
+ {'input': 'Es fácil traducir del español al inglés.'}
30
+ ]), expected_rows=2)
31
+ # The audio generation -> transcription loop on these examples should be simple and clear enough
32
+ # that the unit test can reliably expect the output closely enough to pass these checks.
33
+ results = t.collect()
34
+ assert results[0]['transcription']['text'] in ['I am a banana.', "I'm a banana."]
35
+ assert results[0]['transcription_2']['text'] in ['I am a banana.', "I'm a banana."]
36
+ assert 'easy to translate from Spanish' in results[1]['translation']['text']
37
+ assert 'easy to translate from Spanish' in results[1]['translation_2']['text']
38
+
39
+ def test_chat_completions(self, test_client: pxt.Client) -> None:
40
+ skip_test_if_not_installed('openai')
41
+ TestOpenai.skip_test_if_no_openai_client()
42
+ cl = test_client
43
+ t = cl.create_table('test_tbl', {'input': StringType()})
44
+ from pixeltable.functions.openai import chat_completions
45
+ msgs = [
46
+ {"role": "system", "content": "You are a helpful assistant."},
47
+ {"role": "user", "content": t.input}
48
+ ]
49
+ t.add_column(input_msgs=msgs)
50
+ t.add_column(chat_output=chat_completions(model='gpt-3.5-turbo', messages=t.input_msgs))
51
+ # with inlined messages
52
+ t.add_column(chat_output_2=chat_completions(model='gpt-3.5-turbo', messages=msgs))
53
+ # test a bunch of the parameters
54
+ t.add_column(chat_output_3=chat_completions(
55
+ model='gpt-3.5-turbo', messages=msgs, frequency_penalty=0.1, logprobs=True, top_logprobs=3,
56
+ max_tokens=500, n=3, presence_penalty=0.1, seed=4171780, stop=['\n'], temperature=0.7, top_p=0.8,
57
+ user='pixeltable'
58
+ ))
59
+ # test with JSON output enforced
60
+ t.add_column(chat_output_4=chat_completions(
61
+ model='gpt-3.5-turbo', messages=msgs, response_format={'type': 'json_object'}
62
+ ))
63
+ # TODO Also test the `tools` and `tool_choice` parameters.
64
+ validate_update_status(t.insert(input='Give me an example of a typical JSON structure.'), 1)
65
+ result = t.collect()
66
+ assert len(result['chat_output'][0]['choices'][0]['message']['content']) > 0
67
+ assert len(result['chat_output_2'][0]['choices'][0]['message']['content']) > 0
68
+ assert len(result['chat_output_3'][0]['choices'][0]['message']['content']) > 0
69
+ assert len(result['chat_output_4'][0]['choices'][0]['message']['content']) > 0
70
+
71
+ # When OpenAI gets a request with `response_format` equal to `json_object`, but the prompt does not
72
+ # contain the string "json", it refuses the request.
73
+ # TODO This should probably not be throwing an exception, but rather logging the error in
74
+ # `t.chat_output_4.errormsg` etc.
75
+ with pytest.raises(excs.ExprEvalError) as exc_info:
76
+ t.insert(input='Say something interesting.')
77
+ assert "\\'messages\\' must contain the word \\'json\\'" in str(exc_info.value)
78
+
79
+ def test_gpt_4_vision(self, test_client: pxt.Client) -> None:
80
+ skip_test_if_not_installed('openai')
81
+ TestOpenai.skip_test_if_no_openai_client()
82
+ cl = test_client
83
+ t = cl.create_table('test_tbl', {'prompt': StringType(), 'img': ImageType()})
84
+ from pixeltable.functions.openai import chat_completions, vision
85
+ from pixeltable.functions.string import str_format
86
+ t.add_column(response=vision(prompt="What's in this image?", image=t.img))
87
+ # Also get the response the low-level way, by calling chat_completions
88
+ msgs = [
89
+ {'role': 'user',
90
+ 'content': [
91
+ {'type': 'text', 'text': t.prompt},
92
+ {'type': 'image_url', 'image_url': {
93
+ 'url': str_format('data:image/png;base64,{0}', t.img.b64_encode())
94
+ }}
95
+ ]}
96
+ ]
97
+ t.add_column(response_2=chat_completions(model='gpt-4-vision-preview', messages=msgs, max_tokens=300).choices[0].message.content)
98
+ validate_update_status(t.insert(prompt="What's in this image?", img=SAMPLE_IMAGE_URL), 1)
99
+ result = t.collect()['response_2'][0]
100
+ assert len(result) > 0
101
+
102
+ def test_embeddings(self, test_client: pxt.Client) -> None:
103
+ skip_test_if_not_installed('openai')
104
+ TestOpenai.skip_test_if_no_openai_client()
105
+ cl = test_client
106
+ from pixeltable.functions.openai import embeddings
107
+ t = cl.create_table('test_tbl', {'input': StringType()})
108
+ t.add_column(ada_embed=embeddings(model='text-embedding-ada-002', input=t.input))
109
+ t.add_column(text_3=embeddings(model='text-embedding-3-small', input=t.input, user='pixeltable'))
110
+ validate_update_status(t.insert(input='Say something interesting.'), 1)
111
+ _ = t.head()
112
+
113
+ def test_moderations(self, test_client: pxt.Client) -> None:
114
+ skip_test_if_not_installed('openai')
115
+ TestOpenai.skip_test_if_no_openai_client()
116
+ cl = test_client
117
+ t = cl.create_table('test_tbl', {'input': StringType()})
118
+ from pixeltable.functions.openai import moderations
119
+ t.add_column(moderation=moderations(input=t.input))
120
+ t.add_column(moderation_2=moderations(input=t.input, model='text-moderation-stable'))
121
+ validate_update_status(t.insert(input='Say something interesting.'), 1)
122
+ _ = t.head()
123
+
124
+ def test_image_generations(self, test_client: pxt.Client) -> None:
125
+ skip_test_if_not_installed('openai')
126
+ TestOpenai.skip_test_if_no_openai_client()
127
+ cl = test_client
128
+ t = cl.create_table('test_tbl', {'input': StringType()})
129
+ from pixeltable.functions.openai import image_generations
130
+ t.add_column(img=image_generations(t.input))
131
+ # Test dall-e-2 options
132
+ t.add_column(img_2=image_generations(
133
+ t.input, model='dall-e-2', size='512x512', user='pixeltable'
134
+ ))
135
+ # Test dall-e-3 options
136
+ t.add_column(img_3=image_generations(
137
+ t.input, model='dall-e-3', quality='hd', size='1792x1024', style='natural', user='pixeltable'
138
+ ))
139
+ validate_update_status(t.insert(input='A friendly dinosaur playing tennis in a cornfield'), 1)
140
+ assert t.collect()['img'][0].size == (1024, 1024)
141
+ assert t.collect()['img_2'][0].size == (512, 512)
142
+ assert t.collect()['img_3'][0].size == (1792, 1024)
143
+
144
+ # This ensures that the test will be skipped, rather than returning an error, when no API key is
145
+ # available (for example, when a PR runs in CI).
146
+ @staticmethod
147
+ def skip_test_if_no_openai_client() -> None:
148
+ try:
149
+ import pixeltable.functions.openai
150
+ _ = pixeltable.functions.openai.openai_client()
151
+ except excs.Error as exc:
152
+ pytest.skip(str(exc))
@@ -0,0 +1,111 @@
1
+ import pytest
2
+
3
+ import pixeltable as pxt
4
+ import pixeltable.exceptions as excs
5
+ from pixeltable.tests.utils import skip_test_if_not_installed, validate_update_status
6
+
7
+
8
+ class TestTogether:
9
+
10
+ def test_completions(self, test_client: pxt.Client) -> None:
11
+ skip_test_if_not_installed('together')
12
+ TestTogether.skip_test_if_no_together_client()
13
+ cl = test_client
14
+ t = cl.create_table('test_tbl', {'input': pxt.StringType()})
15
+ from pixeltable.functions.together import completions
16
+ t.add_column(output=completions(prompt=t.input, model='mistralai/Mixtral-8x7B-v0.1', stop=['\n']))
17
+ t.add_column(output_2=completions(
18
+ prompt=t.input,
19
+ model='mistralai/Mixtral-8x7B-v0.1',
20
+ max_tokens=300,
21
+ stop=['\n'],
22
+ temperature=0.7,
23
+ top_p=0.9,
24
+ top_k=40,
25
+ repetition_penalty=1.1,
26
+ logprobs=1,
27
+ echo=True,
28
+ n=3,
29
+ safety_model='Meta-Llama/Llama-Guard-7b'
30
+ ))
31
+ validate_update_status(t.insert(input='I am going to the '), 1)
32
+ result = t.collect()
33
+ assert len(result['output'][0]['choices'][0]['text']) > 0
34
+ assert len(result['output_2'][0]['choices'][0]['text']) > 0
35
+
36
+ def test_chat_completions(self, test_client: pxt.Client) -> None:
37
+ skip_test_if_not_installed('together')
38
+ TestTogether.skip_test_if_no_together_client()
39
+ cl = test_client
40
+ t = cl.create_table('test_tbl', {'input': pxt.StringType()})
41
+ messages = [{'role': 'user', 'content': t.input}]
42
+ from pixeltable.functions.together import chat_completions
43
+ t.add_column(output=chat_completions(messages=messages, model='mistralai/Mixtral-8x7B-v0.1', stop=['\n']))
44
+ t.add_column(output_2=chat_completions(
45
+ messages=messages,
46
+ model='mistralai/Mixtral-8x7B-Instruct-v0.1',
47
+ max_tokens=300,
48
+ stop=['\n'],
49
+ temperature=0.7,
50
+ top_p=0.9,
51
+ top_k=40,
52
+ repetition_penalty=1.1,
53
+ logprobs=1,
54
+ echo=True,
55
+ n=3,
56
+ safety_model='Meta-Llama/Llama-Guard-7b',
57
+ response_format={'type': 'json_object'}
58
+ ))
59
+ validate_update_status(t.insert(input='Give me a typical example of a JSON structure.'), 1)
60
+ result = t.collect()
61
+ assert len(result['output'][0]['choices'][0]['message']) > 0
62
+ assert len(result['output_2'][0]['choices'][0]['message']) > 0
63
+
64
+ def test_embeddings(self, test_client: pxt.Client) -> None:
65
+ skip_test_if_not_installed('together')
66
+ TestTogether.skip_test_if_no_together_client()
67
+ cl = test_client
68
+ t = cl.create_table('test_tbl', {'input': pxt.StringType()})
69
+ from pixeltable.functions.together import embeddings
70
+ t.add_column(embed=embeddings(input=t.input, model='togethercomputer/m2-bert-80M-8k-retrieval'))
71
+ validate_update_status(t.insert(input='Together AI provides a variety of embeddings models.'), 1)
72
+ assert len(t.collect()['embed'][0]) > 0
73
+
74
+ def test_image_generations(self, test_client: pxt.Client) -> None:
75
+ skip_test_if_not_installed('together')
76
+ TestTogether.skip_test_if_no_together_client()
77
+ cl = test_client
78
+ t = cl.create_table(
79
+ 'test_tbl',
80
+ {'input': pxt.StringType(), 'negative_prompt': pxt.StringType(nullable=True)}
81
+ )
82
+ from pixeltable.functions.together import image_generations
83
+ t.add_column(img=image_generations(t.input, model='runwayml/stable-diffusion-v1-5'))
84
+ t.add_column(img_2=image_generations(
85
+ t.input,
86
+ model='stabilityai/stable-diffusion-2-1',
87
+ steps=30,
88
+ seed=4178780,
89
+ height=768,
90
+ width=512,
91
+ negative_prompt=t.negative_prompt
92
+ ))
93
+ validate_update_status(t.insert([
94
+ {'input': 'A friendly dinosaur playing tennis in a cornfield'},
95
+ {'input': 'A friendly dinosaur playing tennis in a cornfield',
96
+ 'negative_prompt': 'tennis court'}
97
+ ]), 2)
98
+ assert t.collect()['img'][0].size == (512, 512)
99
+ assert t.collect()['img_2'][0].size == (512, 768)
100
+ assert t.collect()['img'][1].size == (512, 512)
101
+ assert t.collect()['img_2'][1].size == (512, 768)
102
+
103
+ # This ensures that the test will be skipped, rather than returning an error, when no API key is
104
+ # available (for example, when a PR runs in CI).
105
+ @staticmethod
106
+ def skip_test_if_no_together_client() -> None:
107
+ try:
108
+ import pixeltable.functions.together
109
+ _ = pixeltable.functions.together.together_client()
110
+ except excs.Error as exc:
111
+ pytest.skip(str(exc))
@@ -0,0 +1,65 @@
1
+ from typing import Optional
2
+
3
+ import av
4
+
5
+ import pixeltable as pxt
6
+ import pixeltable.env as env
7
+ from pixeltable.tests.utils import get_video_files, get_audio_files
8
+ from pixeltable.type_system import VideoType, AudioType
9
+ from pixeltable.utils.media_store import MediaStore
10
+
11
+
12
+ class TestAudio:
13
+ def check_audio_params(self, path: str, format: Optional[str] = None, codec: Optional[str] = None):
14
+ with av.open(path) as container:
15
+ audio_stream = container.streams.audio[0]
16
+ if format is not None:
17
+ assert format == container.format.name
18
+ if codec is not None:
19
+ assert codec == audio_stream.codec_context.codec.name
20
+
21
+ def test_basic(self, test_client: pxt.Client) -> None:
22
+ audio_filepaths = get_audio_files()
23
+ cl = test_client
24
+ audio_t = cl.create_table('audio', {'audio_file': AudioType()})
25
+ status = audio_t.insert({'audio_file': p} for p in audio_filepaths)
26
+ assert status.num_rows == len(audio_filepaths)
27
+ assert status.num_excs == 0
28
+ paths = audio_t.select(output=audio_t.audio_file.localpath).collect()['output']
29
+ assert set(paths) == set(audio_filepaths)
30
+
31
+ def test_extract(self, test_client: pxt.Client) -> None:
32
+ video_filepaths = get_video_files()
33
+ cl = test_client
34
+ video_t = cl.create_table('videos', {'video': VideoType()})
35
+ from pixeltable.functions.video import extract_audio
36
+ video_t.add_column(audio=extract_audio(video_t.video))
37
+
38
+ # one of the 3 videos doesn't have audio
39
+ status = video_t.insert({'video': p} for p in video_filepaths)
40
+ assert status.num_rows == len(video_filepaths)
41
+ assert status.num_excs == 0
42
+ assert MediaStore.count(video_t.get_id()) == len(video_filepaths) - 1
43
+ assert video_t.where(video_t.audio != None).count() == len(video_filepaths) - 1
44
+ assert env.Env.get().num_tmp_files() == 0
45
+
46
+ # make sure everything works with a fresh client
47
+ cl = pxt.Client()
48
+ video_t = cl.get_table('videos')
49
+ assert video_t.where(video_t.audio != None).count() == len(video_filepaths) - 1
50
+
51
+ # test generating different formats and codecs
52
+ paths = video_t.select(output=extract_audio(video_t.video, format='wav', codec='pcm_s16le')).collect()['output']
53
+ # media files that are created as a part of a query end up in the tmp dir
54
+ assert env.Env.get().num_tmp_files() == video_t.where(video_t.audio != None).count()
55
+ for path in [p for p in paths if p is not None]:
56
+ self.check_audio_params(path, format='wav', codec='pcm_s16le')
57
+ # higher resolution
58
+ paths = video_t.select(output=extract_audio(video_t.video, format='wav', codec='pcm_s32le')).collect()['output']
59
+ for path in [p for p in paths if p is not None]:
60
+ self.check_audio_params(path, format='wav', codec='pcm_s32le')
61
+
62
+ for format in ['mp3', 'flac']:
63
+ paths = video_t.select(output=extract_audio(video_t.video, format=format)).collect()['output']
64
+ for path in [p for p in paths if p is not None]:
65
+ self.check_audio_params(path, format=format)
@@ -0,0 +1,27 @@
1
+ from pixeltable.catalog import is_valid_identifier, is_valid_path
2
+
3
+ class TestCatalog:
4
+ """Tests for miscellanous catalog functions."""
5
+ def test_valid_identifier(self) -> None:
6
+ valid_ids = ['a', 'a1', 'a_1', 'a_']
7
+ invalid_ids = ['', '_', '__', '_a', '1a', 'a.b', '.a', 'a-b']
8
+ for valid_id in valid_ids:
9
+ assert is_valid_identifier(valid_id), valid_ids
10
+
11
+ for invalid_id in invalid_ids:
12
+ assert not is_valid_identifier(invalid_id), invalid_ids
13
+
14
+ def test_valid_path(self) -> None:
15
+ assert is_valid_path('', empty_is_valid=True)
16
+ assert not is_valid_path('', empty_is_valid=False)
17
+
18
+ valid_paths = ['a', 'a_.b_', 'a.b.c', 'a.b.c.d']
19
+ invalid_paths = ['.', '..', 'a.', '.a', 'a..b']
20
+
21
+ for valid_path in valid_paths:
22
+ assert is_valid_path(valid_path, empty_is_valid=False), valid_path
23
+ assert is_valid_path(valid_path, empty_is_valid=True), valid_path
24
+
25
+ for invalid_path in invalid_paths:
26
+ assert not is_valid_path(invalid_path, empty_is_valid=False), invalid_path
27
+ assert not is_valid_path(invalid_path, empty_is_valid=True), invalid_path
@@ -1,21 +1,21 @@
1
1
  import pytest
2
2
 
3
- import pixeltable as pt
4
- from pixeltable import exceptions as exc
3
+ import pixeltable as pxt
4
+ import pixeltable.exceptions as excs
5
5
 
6
6
 
7
7
  class TestClient:
8
- def test_create_db(self, init_db: None) -> None:
9
- cl = pt.Client()
10
- _ = cl.create_db('test')
11
- with pytest.raises(exc.DuplicateNameError):
12
- _ = cl.create_db('test')
8
+ def test_list_functions(self, init_env) -> None:
9
+ cl = pxt.Client()
10
+ _ = cl.list_functions()
11
+ print(_)
13
12
 
14
- _ = cl.get_db('test')
15
- with pytest.raises(exc.UnknownEntityError):
16
- _ = cl.get_db('xyz')
17
-
18
- cl.drop_db('test', force=True)
19
- with pytest.raises(exc.UnknownEntityError):
20
- cl.drop_db('test', force=True)
13
+ def test_drop_table(self, test_tbl: pxt.Table) -> None:
14
+ cl = pxt.Client()
15
+ t = cl.get_table('test_tbl')
16
+ cl.drop_table('test_tbl')
17
+ with pytest.raises(excs.Error):
18
+ _ = cl.get_table('test_tbl')
19
+ with pytest.raises(excs.Error):
20
+ _ = t.show(1)
21
21