pixeltable 0.3.10__py3-none-any.whl → 0.3.11__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 +1 -1
- pixeltable/__version__.py +2 -2
- pixeltable/catalog/__init__.py +2 -1
- pixeltable/catalog/catalog.py +63 -36
- pixeltable/catalog/column.py +6 -4
- pixeltable/catalog/dir.py +5 -5
- pixeltable/catalog/globals.py +12 -14
- pixeltable/catalog/insertable_table.py +4 -7
- pixeltable/catalog/path.py +2 -2
- pixeltable/catalog/table.py +64 -56
- pixeltable/catalog/table_version.py +42 -40
- pixeltable/catalog/table_version_handle.py +3 -0
- pixeltable/catalog/table_version_path.py +1 -1
- pixeltable/catalog/view.py +8 -7
- pixeltable/dataframe.py +5 -3
- pixeltable/env.py +108 -42
- pixeltable/exec/__init__.py +2 -0
- pixeltable/exec/aggregation_node.py +6 -8
- pixeltable/exec/cache_prefetch_node.py +4 -7
- pixeltable/exec/component_iteration_node.py +1 -3
- pixeltable/exec/data_row_batch.py +1 -2
- pixeltable/exec/exec_context.py +1 -1
- pixeltable/exec/exec_node.py +1 -2
- pixeltable/exec/expr_eval/__init__.py +2 -0
- pixeltable/exec/expr_eval/evaluators.py +137 -20
- pixeltable/exec/expr_eval/expr_eval_node.py +43 -64
- pixeltable/exec/expr_eval/globals.py +68 -7
- pixeltable/exec/expr_eval/schedulers.py +25 -23
- pixeltable/exec/in_memory_data_node.py +8 -6
- pixeltable/exec/row_update_node.py +3 -4
- pixeltable/exec/sql_node.py +16 -17
- pixeltable/exprs/__init__.py +1 -1
- pixeltable/exprs/column_property_ref.py +1 -1
- pixeltable/exprs/column_ref.py +3 -3
- pixeltable/exprs/compound_predicate.py +1 -1
- pixeltable/exprs/data_row.py +17 -1
- pixeltable/exprs/expr.py +12 -12
- pixeltable/exprs/function_call.py +34 -2
- pixeltable/exprs/json_mapper.py +95 -48
- pixeltable/exprs/json_path.py +3 -4
- pixeltable/exprs/method_ref.py +2 -2
- pixeltable/exprs/object_ref.py +2 -2
- pixeltable/exprs/row_builder.py +33 -6
- pixeltable/exprs/similarity_expr.py +1 -1
- pixeltable/exprs/sql_element_cache.py +1 -1
- pixeltable/exprs/string_op.py +2 -2
- pixeltable/ext/__init__.py +1 -1
- pixeltable/ext/functions/__init__.py +1 -1
- pixeltable/ext/functions/whisperx.py +1 -1
- pixeltable/ext/functions/yolox.py +1 -1
- pixeltable/func/aggregate_function.py +1 -1
- pixeltable/func/callable_function.py +2 -5
- pixeltable/func/expr_template_function.py +22 -2
- pixeltable/func/function.py +4 -5
- pixeltable/func/function_registry.py +1 -1
- pixeltable/func/signature.py +1 -1
- pixeltable/func/udf.py +2 -2
- pixeltable/functions/__init__.py +1 -1
- pixeltable/functions/anthropic.py +2 -2
- pixeltable/functions/audio.py +1 -1
- pixeltable/functions/deepseek.py +1 -1
- pixeltable/functions/fireworks.py +1 -1
- pixeltable/functions/globals.py +6 -6
- pixeltable/functions/huggingface.py +1 -1
- pixeltable/functions/image.py +1 -1
- pixeltable/functions/json.py +1 -1
- pixeltable/functions/llama_cpp.py +1 -1
- pixeltable/functions/math.py +1 -1
- pixeltable/functions/mistralai.py +1 -1
- pixeltable/functions/ollama.py +1 -1
- pixeltable/functions/openai.py +2 -2
- pixeltable/functions/replicate.py +1 -1
- pixeltable/functions/string.py +1 -1
- pixeltable/functions/timestamp.py +1 -1
- pixeltable/functions/together.py +1 -1
- pixeltable/functions/util.py +1 -1
- pixeltable/functions/video.py +2 -2
- pixeltable/functions/vision.py +2 -2
- pixeltable/index/embedding_index.py +12 -1
- pixeltable/io/__init__.py +5 -3
- pixeltable/io/fiftyone.py +6 -7
- pixeltable/io/label_studio.py +21 -20
- pixeltable/io/pandas.py +6 -5
- pixeltable/iterators/__init__.py +1 -1
- pixeltable/metadata/__init__.py +5 -3
- pixeltable/metadata/converters/convert_24.py +3 -3
- pixeltable/metadata/converters/convert_25.py +1 -1
- pixeltable/metadata/converters/convert_29.py +1 -1
- pixeltable/store.py +2 -2
- pixeltable/type_system.py +19 -7
- pixeltable/utils/console_output.py +3 -2
- pixeltable/utils/coroutine.py +3 -3
- pixeltable/utils/dbms.py +66 -0
- pixeltable/utils/documents.py +61 -67
- pixeltable/utils/filecache.py +1 -1
- pixeltable/utils/http_server.py +3 -2
- pixeltable/utils/pytorch.py +1 -1
- pixeltable/utils/sql.py +1 -1
- pixeltable-0.3.11.dist-info/METADATA +436 -0
- pixeltable-0.3.11.dist-info/RECORD +179 -0
- pixeltable/catalog/path_dict.py +0 -169
- pixeltable-0.3.10.dist-info/METADATA +0 -382
- pixeltable-0.3.10.dist-info/RECORD +0 -179
- {pixeltable-0.3.10.dist-info → pixeltable-0.3.11.dist-info}/LICENSE +0 -0
- {pixeltable-0.3.10.dist-info → pixeltable-0.3.11.dist-info}/WHEEL +0 -0
- {pixeltable-0.3.10.dist-info → pixeltable-0.3.11.dist-info}/entry_points.txt +0 -0
pixeltable/functions/globals.py
CHANGED
|
@@ -23,7 +23,7 @@ T = typing.TypeVar('T')
|
|
|
23
23
|
class sum(func.Aggregator, typing.Generic[T]):
|
|
24
24
|
"""Sums the selected integers or floats."""
|
|
25
25
|
|
|
26
|
-
def __init__(self):
|
|
26
|
+
def __init__(self) -> None:
|
|
27
27
|
self.sum: T = None
|
|
28
28
|
|
|
29
29
|
def update(self, val: T) -> None:
|
|
@@ -67,7 +67,7 @@ def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
|
|
|
67
67
|
),
|
|
68
68
|
)
|
|
69
69
|
class count(func.Aggregator, typing.Generic[T]):
|
|
70
|
-
def __init__(self):
|
|
70
|
+
def __init__(self) -> None:
|
|
71
71
|
self.count = 0
|
|
72
72
|
|
|
73
73
|
def update(self, val: T) -> None:
|
|
@@ -88,7 +88,7 @@ def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
|
|
|
88
88
|
type_substitutions=tuple({T: Optional[t]} for t in (str, int, float, bool, ts.Timestamp)), # type: ignore[misc]
|
|
89
89
|
)
|
|
90
90
|
class min(func.Aggregator, typing.Generic[T]):
|
|
91
|
-
def __init__(self):
|
|
91
|
+
def __init__(self) -> None:
|
|
92
92
|
self.val: T = None
|
|
93
93
|
|
|
94
94
|
def update(self, val: T) -> None:
|
|
@@ -118,7 +118,7 @@ def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
|
|
|
118
118
|
type_substitutions=tuple({T: Optional[t]} for t in (str, int, float, bool, ts.Timestamp)), # type: ignore[misc]
|
|
119
119
|
)
|
|
120
120
|
class max(func.Aggregator, typing.Generic[T]):
|
|
121
|
-
def __init__(self):
|
|
121
|
+
def __init__(self) -> None:
|
|
122
122
|
self.val: T = None
|
|
123
123
|
|
|
124
124
|
def update(self, val: T) -> None:
|
|
@@ -143,7 +143,7 @@ def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
|
|
|
143
143
|
|
|
144
144
|
@func.uda(type_substitutions=({T: Optional[int]}, {T: Optional[float]})) # type: ignore[misc]
|
|
145
145
|
class mean(func.Aggregator, typing.Generic[T]):
|
|
146
|
-
def __init__(self):
|
|
146
|
+
def __init__(self) -> None:
|
|
147
147
|
self.sum: T = None
|
|
148
148
|
self.count = 0
|
|
149
149
|
|
|
@@ -182,5 +182,5 @@ def map(expr: exprs.Expr, fn: Callable[[exprs.Expr], Any]) -> exprs.Expr:
|
|
|
182
182
|
__all__ = local_public_names(__name__)
|
|
183
183
|
|
|
184
184
|
|
|
185
|
-
def __dir__():
|
|
185
|
+
def __dir__() -> list[str]:
|
|
186
186
|
return __all__
|
pixeltable/functions/image.py
CHANGED
pixeltable/functions/json.py
CHANGED
pixeltable/functions/math.py
CHANGED
pixeltable/functions/ollama.py
CHANGED
pixeltable/functions/openai.py
CHANGED
|
@@ -122,7 +122,7 @@ class OpenAIRateLimitsInfo(env.RateLimitsInfo):
|
|
|
122
122
|
_header_duration_pattern = re.compile(r'(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)ms)|(?:(\d+)m)?(?:([\d.]+)s)?')
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def _parse_header_duration(duration_str):
|
|
125
|
+
def _parse_header_duration(duration_str: str) -> datetime.timedelta:
|
|
126
126
|
match = _header_duration_pattern.match(duration_str)
|
|
127
127
|
if not match:
|
|
128
128
|
raise ValueError('Invalid duration format')
|
|
@@ -837,5 +837,5 @@ def _opt(arg: _T) -> Union[_T, 'openai.NotGiven']:
|
|
|
837
837
|
__all__ = local_public_names(__name__)
|
|
838
838
|
|
|
839
839
|
|
|
840
|
-
def __dir__():
|
|
840
|
+
def __dir__() -> list[str]:
|
|
841
841
|
return __all__
|
pixeltable/functions/string.py
CHANGED
pixeltable/functions/together.py
CHANGED
pixeltable/functions/util.py
CHANGED
|
@@ -21,7 +21,7 @@ def normalize_image_mode(image: PIL.Image.Image) -> PIL.Image.Image:
|
|
|
21
21
|
Converts grayscale images to 3-channel for compatibility with models that only work with
|
|
22
22
|
multichannel input.
|
|
23
23
|
"""
|
|
24
|
-
if image.mode in
|
|
24
|
+
if image.mode in ('1', 'L'):
|
|
25
25
|
return image.convert('RGB')
|
|
26
26
|
if image.mode == 'LA':
|
|
27
27
|
return image.convert('RGBA')
|
pixeltable/functions/video.py
CHANGED
|
@@ -143,7 +143,7 @@ def _get_metadata(path: str) -> dict:
|
|
|
143
143
|
|
|
144
144
|
|
|
145
145
|
def __get_stream_metadata(stream: av.stream.Stream) -> dict:
|
|
146
|
-
if stream.type not in
|
|
146
|
+
if stream.type not in ('audio', 'video'):
|
|
147
147
|
return {'type': stream.type} # Currently unsupported
|
|
148
148
|
|
|
149
149
|
codec_context = stream.codec_context
|
|
@@ -190,5 +190,5 @@ def __get_stream_metadata(stream: av.stream.Stream) -> dict:
|
|
|
190
190
|
__all__ = local_public_names(__name__)
|
|
191
191
|
|
|
192
192
|
|
|
193
|
-
def __dir__():
|
|
193
|
+
def __dir__() -> list[str]:
|
|
194
194
|
return __all__
|
pixeltable/functions/vision.py
CHANGED
|
@@ -238,7 +238,7 @@ class mean_ap(pxt.Aggregator):
|
|
|
238
238
|
- A `dict[int, float]` mapping each label class to an average precision (AP) value for that class.
|
|
239
239
|
"""
|
|
240
240
|
|
|
241
|
-
def __init__(self):
|
|
241
|
+
def __init__(self) -> None:
|
|
242
242
|
self.class_tpfp: dict[int, list[dict]] = defaultdict(list)
|
|
243
243
|
|
|
244
244
|
def update(self, eval_dicts: list[dict]) -> None:
|
|
@@ -394,5 +394,5 @@ def draw_bounding_boxes(
|
|
|
394
394
|
__all__ = local_public_names(__name__)
|
|
395
395
|
|
|
396
396
|
|
|
397
|
-
def __dir__():
|
|
397
|
+
def __dir__() -> list[str]:
|
|
398
398
|
return __all__
|
|
@@ -208,7 +208,18 @@ class EmbeddingIndex(IndexBase):
|
|
|
208
208
|
and len(sig.required_parameters) <= 1
|
|
209
209
|
and sig.parameters_by_pos[0].col_type.type_enum == expected_type
|
|
210
210
|
):
|
|
211
|
-
|
|
211
|
+
# We found a valid signature. Now, if it has more than one parameter, we need to transform it into a
|
|
212
|
+
# 1-ary function by fixing all the other parameters to their defaults. This is to ensure that
|
|
213
|
+
# conditional_return_type resolves correctly.
|
|
214
|
+
if len(sig.parameters) == 1:
|
|
215
|
+
unary_fn = resolved_fn
|
|
216
|
+
else:
|
|
217
|
+
assert all(sig.parameters_by_pos[i].has_default for i in range(1, len(sig.parameters)))
|
|
218
|
+
defaults = {param.name: param.default for param in sig.parameters_by_pos[1:]}
|
|
219
|
+
unary_fn = resolved_fn.using(**defaults)
|
|
220
|
+
assert not unary_fn.is_polymorphic
|
|
221
|
+
assert len(unary_fn.signature.parameters) == 1
|
|
222
|
+
return unary_fn
|
|
212
223
|
return None
|
|
213
224
|
|
|
214
225
|
@classmethod
|
pixeltable/io/__init__.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# ruff: noqa: F401
|
|
2
|
+
|
|
1
3
|
from .datarows import import_json, import_rows
|
|
2
4
|
from .external_store import ExternalStore, SyncStatus
|
|
3
5
|
from .globals import create_label_studio_project, export_images_as_fo_dataset
|
|
@@ -5,10 +7,10 @@ from .hf_datasets import import_huggingface_dataset
|
|
|
5
7
|
from .pandas import import_csv, import_excel, import_pandas
|
|
6
8
|
from .parquet import export_parquet, import_parquet
|
|
7
9
|
|
|
8
|
-
__default_dir =
|
|
10
|
+
__default_dir = {symbol for symbol in dir() if not symbol.startswith('_')}
|
|
9
11
|
__removed_symbols = {'globals', 'hf_datasets', 'pandas', 'parquet', 'datarows'}
|
|
10
|
-
__all__ = sorted(
|
|
12
|
+
__all__ = sorted(__default_dir - __removed_symbols)
|
|
11
13
|
|
|
12
14
|
|
|
13
|
-
def __dir__():
|
|
15
|
+
def __dir__() -> list[str]:
|
|
14
16
|
return __all__
|
pixeltable/io/fiftyone.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from typing import Iterator, Optional, Union
|
|
2
|
+
from typing import Any, Iterator, Optional, Union
|
|
3
3
|
|
|
4
4
|
import fiftyone as fo # type: ignore[import-untyped]
|
|
5
5
|
import fiftyone.utils.data as foud # type: ignore[import-untyped]
|
|
@@ -59,10 +59,9 @@ class PxtImageDatasetImporter(foud.LabeledImageDatasetImporter):
|
|
|
59
59
|
for exprs_, label_cls, default_name in label_categories:
|
|
60
60
|
if exprs_ is None or isinstance(exprs_, dict):
|
|
61
61
|
continue
|
|
62
|
-
if isinstance(exprs_, exprs.Expr)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for expr in exprs_:
|
|
62
|
+
exprs_list = [exprs_] if isinstance(exprs_, exprs.Expr) else exprs_
|
|
63
|
+
assert isinstance(exprs_list, list)
|
|
64
|
+
for expr in exprs_list:
|
|
66
65
|
if default_name not in self.__labels:
|
|
67
66
|
name = default_name
|
|
68
67
|
else:
|
|
@@ -125,7 +124,7 @@ class PxtImageDatasetImporter(foud.LabeledImageDatasetImporter):
|
|
|
125
124
|
elif label_cls is fo.Detections:
|
|
126
125
|
label = fo.Detections(detections=self.__as_fo_detections(label_data))
|
|
127
126
|
else:
|
|
128
|
-
|
|
127
|
+
raise AssertionError()
|
|
129
128
|
labels[label_name] = label
|
|
130
129
|
|
|
131
130
|
return file, metadata, labels
|
|
@@ -166,5 +165,5 @@ class PxtImageDatasetImporter(foud.LabeledImageDatasetImporter):
|
|
|
166
165
|
def get_dataset_info(self) -> dict:
|
|
167
166
|
pass
|
|
168
167
|
|
|
169
|
-
def close(self, *args) -> None:
|
|
168
|
+
def close(self, *args: Any) -> None:
|
|
170
169
|
pass
|
pixeltable/io/label_studio.py
CHANGED
|
@@ -5,16 +5,14 @@ import os
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
from typing import Any, Iterator, Literal, Optional, cast
|
|
8
|
-
from xml.etree import ElementTree
|
|
8
|
+
from xml.etree import ElementTree as ET
|
|
9
9
|
|
|
10
10
|
import label_studio_sdk # type: ignore[import-untyped]
|
|
11
11
|
import PIL.Image
|
|
12
12
|
from requests.exceptions import HTTPError
|
|
13
13
|
|
|
14
14
|
import pixeltable as pxt
|
|
15
|
-
import
|
|
16
|
-
import pixeltable.exceptions as excs
|
|
17
|
-
from pixeltable import Column, Table
|
|
15
|
+
from pixeltable import Column, Table, env, exceptions as excs
|
|
18
16
|
from pixeltable.config import Config
|
|
19
17
|
from pixeltable.exprs import ColumnRef, DataRow, Expr
|
|
20
18
|
from pixeltable.io.external_store import Project, SyncStatus
|
|
@@ -140,7 +138,8 @@ class LabelStudioProject(Project):
|
|
|
140
138
|
page += 1
|
|
141
139
|
if unknown_task_count > 0:
|
|
142
140
|
_logger.warning(
|
|
143
|
-
f'Skipped {unknown_task_count} unrecognized task(s) when syncing
|
|
141
|
+
f'Skipped {unknown_task_count} unrecognized task(s) when syncing '
|
|
142
|
+
f'Label Studio project {self.project_title!r}.'
|
|
144
143
|
)
|
|
145
144
|
|
|
146
145
|
def __update_tasks(self, t: Table, existing_tasks: dict[tuple, dict]) -> SyncStatus:
|
|
@@ -174,11 +173,11 @@ class LabelStudioProject(Project):
|
|
|
174
173
|
# Send media to Label Studio by HTTP post.
|
|
175
174
|
assert len(t_data_cols) == 1 # This was verified when the project was set up
|
|
176
175
|
return self.__update_tasks_by_post(t, existing_tasks, t_data_cols[0], t_rl_cols, rl_info)
|
|
177
|
-
elif self.media_import_method
|
|
176
|
+
elif self.media_import_method in ('file', 'url'):
|
|
178
177
|
# Send media to Label Studio by file reference (local file or URL).
|
|
179
178
|
return self.__update_tasks_by_files(t, existing_tasks, t_data_cols, t_rl_cols, rl_info)
|
|
180
179
|
else:
|
|
181
|
-
|
|
180
|
+
raise AssertionError()
|
|
182
181
|
|
|
183
182
|
def __update_tasks_by_post(
|
|
184
183
|
self,
|
|
@@ -227,7 +226,7 @@ class LabelStudioProject(Project):
|
|
|
227
226
|
)
|
|
228
227
|
for i in range(len(coco_annotations))
|
|
229
228
|
]
|
|
230
|
-
_logger.debug(
|
|
229
|
+
_logger.debug('`predictions`: {%s}', predictions)
|
|
231
230
|
self.project.create_predictions(predictions)
|
|
232
231
|
tasks_created += 1
|
|
233
232
|
|
|
@@ -358,7 +357,7 @@ class LabelStudioProject(Project):
|
|
|
358
357
|
def __localpath_to_lspath(cls, localpath: str) -> str:
|
|
359
358
|
# Transform the local path into Label Studio's bespoke path format.
|
|
360
359
|
relpath = Path(localpath).relative_to(Config.get().home)
|
|
361
|
-
return f'/data/local-files/?d={
|
|
360
|
+
return f'/data/local-files/?d={relpath}'
|
|
362
361
|
|
|
363
362
|
def __delete_stale_tasks(
|
|
364
363
|
self, existing_tasks: dict[tuple, dict], row_ids_in_pxt: set[tuple], tasks_created: int
|
|
@@ -405,7 +404,8 @@ class LabelStudioProject(Project):
|
|
|
405
404
|
updates = [{'_rowid': rowid, local_annotations_col.name: ann} for rowid, ann in annotations.items()]
|
|
406
405
|
if len(updates) > 0:
|
|
407
406
|
_logger.info(
|
|
408
|
-
f'Updating table
|
|
407
|
+
f'Updating table {t._name!r}, column {local_annotations_col.name!r} '
|
|
408
|
+
f'with {len(updates)} total annotations.'
|
|
409
409
|
)
|
|
410
410
|
# batch_update currently doesn't propagate from views to base tables. As a workaround, we call
|
|
411
411
|
# batch_update on the actual ancestor table that holds the annotations column.
|
|
@@ -451,7 +451,7 @@ class LabelStudioProject(Project):
|
|
|
451
451
|
Parses a Label Studio XML config, extracting the names and Pixeltable types of
|
|
452
452
|
all input variables.
|
|
453
453
|
"""
|
|
454
|
-
root:
|
|
454
|
+
root: ET.Element = ET.fromstring(xml_config)
|
|
455
455
|
if root.tag.lower() != 'view':
|
|
456
456
|
raise excs.Error('Root of Label Studio config must be a `View`')
|
|
457
457
|
config = _LabelStudioConfig(
|
|
@@ -461,7 +461,7 @@ class LabelStudioProject(Project):
|
|
|
461
461
|
return config
|
|
462
462
|
|
|
463
463
|
@classmethod
|
|
464
|
-
def __parse_data_keys_config(cls, root:
|
|
464
|
+
def __parse_data_keys_config(cls, root: ET.Element) -> dict[str, '_DataKey']:
|
|
465
465
|
"""Parses the data keys from a Label Studio XML config."""
|
|
466
466
|
config: dict[str, '_DataKey'] = {}
|
|
467
467
|
for element in root:
|
|
@@ -477,7 +477,7 @@ class LabelStudioProject(Project):
|
|
|
477
477
|
return config
|
|
478
478
|
|
|
479
479
|
@classmethod
|
|
480
|
-
def __parse_rectangle_labels_config(cls, root:
|
|
480
|
+
def __parse_rectangle_labels_config(cls, root: ET.Element) -> dict[str, '_RectangleLabel']:
|
|
481
481
|
"""Parses the RectangleLabels from a Label Studio XML config."""
|
|
482
482
|
config: dict[str, '_RectangleLabel'] = {}
|
|
483
483
|
for element in root:
|
|
@@ -534,7 +534,7 @@ class LabelStudioProject(Project):
|
|
|
534
534
|
_label_studio_client().delete_project(self.project_id)
|
|
535
535
|
env.Env.get().console_logger.info(f'Deleted Label Studio project: {title}')
|
|
536
536
|
|
|
537
|
-
def __eq__(self, other) -> bool:
|
|
537
|
+
def __eq__(self, other: object) -> bool:
|
|
538
538
|
return isinstance(other, LabelStudioProject) and self.project_id == other.project_id
|
|
539
539
|
|
|
540
540
|
def __hash__(self) -> int:
|
|
@@ -576,7 +576,7 @@ class LabelStudioProject(Project):
|
|
|
576
576
|
local_annotations_column = ANNOTATIONS_COLUMN
|
|
577
577
|
else:
|
|
578
578
|
local_annotations_column = next(k for k, v in col_mapping.items() if v == ANNOTATIONS_COLUMN)
|
|
579
|
-
if local_annotations_column not in t._schema
|
|
579
|
+
if local_annotations_column not in t._schema:
|
|
580
580
|
t.add_columns({local_annotations_column: pxt.JsonType(nullable=True)})
|
|
581
581
|
|
|
582
582
|
resolved_col_mapping = cls.validate_columns(
|
|
@@ -591,9 +591,9 @@ class LabelStudioProject(Project):
|
|
|
591
591
|
if media_import_method != 'url':
|
|
592
592
|
raise excs.Error("`s3_configuration` is only valid when `media_import_method == 'url'`")
|
|
593
593
|
s3_configuration = copy.copy(s3_configuration)
|
|
594
|
-
if
|
|
594
|
+
if 'bucket' not in s3_configuration:
|
|
595
595
|
raise excs.Error('`s3_configuration` must contain a `bucket` field')
|
|
596
|
-
if
|
|
596
|
+
if 'title' not in s3_configuration:
|
|
597
597
|
s3_configuration['title'] = 'Pixeltable-S3-Import-Storage'
|
|
598
598
|
if (
|
|
599
599
|
'aws_access_key_id' not in s3_configuration
|
|
@@ -633,7 +633,8 @@ class LabelStudioProject(Project):
|
|
|
633
633
|
raise excs.Error(
|
|
634
634
|
'`media_import_method` is set to `file`, but your Label Studio server is not configured '
|
|
635
635
|
'for local file storage.\nPlease set the `LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED` '
|
|
636
|
-
'environment variable to `true` in the environment where your Label Studio server
|
|
636
|
+
'environment variable to `true` in the environment where your Label Studio server '
|
|
637
|
+
'is running.'
|
|
637
638
|
) from exc
|
|
638
639
|
raise # Handle any other exception type normally
|
|
639
640
|
|
|
@@ -663,7 +664,7 @@ class _LabelStudioConfig:
|
|
|
663
664
|
rectangle_labels: dict[str, _RectangleLabel]
|
|
664
665
|
|
|
665
666
|
def validate(self) -> None:
|
|
666
|
-
data_key_names =
|
|
667
|
+
data_key_names = {key.name for key in self.data_keys.values() if key.name is not None}
|
|
667
668
|
for name, rl in self.rectangle_labels.items():
|
|
668
669
|
if rl.to_name not in data_key_names:
|
|
669
670
|
raise excs.Error(
|
|
@@ -674,7 +675,7 @@ class _LabelStudioConfig:
|
|
|
674
675
|
@property
|
|
675
676
|
def export_columns(self) -> dict[str, pxt.ColumnType]:
|
|
676
677
|
data_key_cols = {key_id: key_info.column_type for key_id, key_info in self.data_keys.items()}
|
|
677
|
-
rl_cols = {name: pxt.JsonType() for name in self.rectangle_labels
|
|
678
|
+
rl_cols = {name: pxt.JsonType() for name in self.rectangle_labels}
|
|
678
679
|
return {**data_key_cols, **rl_cols}
|
|
679
680
|
|
|
680
681
|
|
pixeltable/io/pandas.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os
|
|
1
2
|
from typing import Any, Optional, Union
|
|
2
3
|
|
|
3
4
|
import numpy as np
|
|
@@ -52,12 +53,12 @@ def import_pandas(
|
|
|
52
53
|
|
|
53
54
|
def import_csv(
|
|
54
55
|
tbl_name: str,
|
|
55
|
-
filepath_or_buffer,
|
|
56
|
+
filepath_or_buffer: Union[str, os.PathLike],
|
|
56
57
|
schema_overrides: Optional[dict[str, Any]] = None,
|
|
57
58
|
primary_key: Optional[Union[str, list[str]]] = None,
|
|
58
59
|
num_retained_versions: int = 10,
|
|
59
60
|
comment: str = '',
|
|
60
|
-
**kwargs,
|
|
61
|
+
**kwargs: Any,
|
|
61
62
|
) -> pxt.Table:
|
|
62
63
|
"""
|
|
63
64
|
Creates a new base table from a csv file. This is a convenience method and is equivalent
|
|
@@ -81,13 +82,13 @@ def import_csv(
|
|
|
81
82
|
|
|
82
83
|
def import_excel(
|
|
83
84
|
tbl_name: str,
|
|
84
|
-
io,
|
|
85
|
-
|
|
85
|
+
io: Union[str, os.PathLike],
|
|
86
|
+
*,
|
|
86
87
|
schema_overrides: Optional[dict[str, Any]] = None,
|
|
87
88
|
primary_key: Optional[Union[str, list[str]]] = None,
|
|
88
89
|
num_retained_versions: int = 10,
|
|
89
90
|
comment: str = '',
|
|
90
|
-
**kwargs,
|
|
91
|
+
**kwargs: Any,
|
|
91
92
|
) -> pxt.Table:
|
|
92
93
|
"""
|
|
93
94
|
Creates a new base table from an Excel (.xlsx) file. This is a convenience method and is
|
pixeltable/iterators/__init__.py
CHANGED
pixeltable/metadata/__init__.py
CHANGED
|
@@ -24,9 +24,11 @@ def create_system_info(engine: sql.engine.Engine) -> None:
|
|
|
24
24
|
system_md = SystemInfoMd(schema_version=VERSION)
|
|
25
25
|
record = SystemInfo(md=dataclasses.asdict(system_md))
|
|
26
26
|
with orm.Session(engine, future=True) as session:
|
|
27
|
-
|
|
28
|
-
session.
|
|
29
|
-
|
|
27
|
+
# Write system metadata only once for idempotency
|
|
28
|
+
if session.query(SystemInfo).count() == 0:
|
|
29
|
+
session.add(record)
|
|
30
|
+
session.flush()
|
|
31
|
+
session.commit()
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
# conversion functions for upgrading the metadata schema from one version to the following
|
|
@@ -19,11 +19,11 @@ def __substitute_md(k: Optional[str], v: Any) -> Optional[tuple[Optional[str], A
|
|
|
19
19
|
isinstance(v, dict)
|
|
20
20
|
and '_classpath' in v
|
|
21
21
|
and v['_classpath']
|
|
22
|
-
in
|
|
22
|
+
in (
|
|
23
23
|
'pixeltable.func.callable_function.CallableFunction',
|
|
24
24
|
'pixeltable.func.aggregate_function.AggregateFunction',
|
|
25
25
|
'pixeltable.func.expr_template_function.ExprTemplateFunction',
|
|
26
|
-
|
|
26
|
+
)
|
|
27
27
|
):
|
|
28
28
|
if 'path' in v:
|
|
29
29
|
assert 'signature' not in v
|
|
@@ -50,6 +50,6 @@ def __substitute_path(path: str) -> str:
|
|
|
50
50
|
# versions, it's necessary to resolve the function symbol to get the signature. The following
|
|
51
51
|
# adjustment is necessary for function names that are stored in db artifacts of version < 25, but
|
|
52
52
|
# have changed in some version > 25.
|
|
53
|
-
if path in
|
|
53
|
+
if path in ('pixeltable.functions.huggingface.clip_text', 'pixeltable.functions.huggingface.clip_image'):
|
|
54
54
|
return 'pixeltable.functions.huggingface.clip'
|
|
55
55
|
return path
|
|
@@ -13,7 +13,7 @@ def _(engine: sql.engine.Engine) -> None:
|
|
|
13
13
|
|
|
14
14
|
def __substitute_md(k: Optional[str], v: Any) -> Optional[tuple[Optional[str], Any]]:
|
|
15
15
|
if k == 'path' and (
|
|
16
|
-
v in
|
|
16
|
+
v in ('pixeltable.functions.huggingface.clip_text', 'pixeltable.functions.huggingface.clip_image')
|
|
17
17
|
):
|
|
18
18
|
return 'path', 'pixeltable.functions.huggingface.clip'
|
|
19
19
|
return None
|
|
@@ -80,7 +80,7 @@ def __substitute_md(k: Optional[str], v: Any) -> Optional[tuple[Optional[str], A
|
|
|
80
80
|
rolled_kwargs = kwargs.pop(param['name'])
|
|
81
81
|
|
|
82
82
|
if rolled_args is not None:
|
|
83
|
-
assert rolled_args['_classname'] in
|
|
83
|
+
assert rolled_args['_classname'] in ('InlineArray', 'InlineList')
|
|
84
84
|
new_args.extend(rolled_args['components'])
|
|
85
85
|
if rolled_kwargs is not None:
|
|
86
86
|
assert rolled_kwargs['_classname'] == 'InlineDict'
|
pixeltable/store.py
CHANGED
|
@@ -99,9 +99,9 @@ class StoreBase:
|
|
|
99
99
|
|
|
100
100
|
# v_min/v_max indices: speeds up base table scans needed to propagate a base table insert or delete
|
|
101
101
|
idx_name = f'vmin_idx_{self.tbl_version.id.hex}'
|
|
102
|
-
idxs.append(sql.Index(idx_name, self.v_min_col, postgresql_using=
|
|
102
|
+
idxs.append(sql.Index(idx_name, self.v_min_col, postgresql_using=Env.get().dbms.version_index_type))
|
|
103
103
|
idx_name = f'vmax_idx_{self.tbl_version.id.hex}'
|
|
104
|
-
idxs.append(sql.Index(idx_name, self.v_max_col, postgresql_using=
|
|
104
|
+
idxs.append(sql.Index(idx_name, self.v_max_col, postgresql_using=Env.get().dbms.version_index_type))
|
|
105
105
|
|
|
106
106
|
self.sa_tbl = sql.Table(self._storage_name(), self.sa_md, *all_cols, *idxs)
|
|
107
107
|
|
pixeltable/type_system.py
CHANGED
|
@@ -512,7 +512,7 @@ class StringType(ColumnType):
|
|
|
512
512
|
def __init__(self, nullable: bool = False):
|
|
513
513
|
super().__init__(self.Type.STRING, nullable=nullable)
|
|
514
514
|
|
|
515
|
-
def has_supertype(self):
|
|
515
|
+
def has_supertype(self) -> bool:
|
|
516
516
|
return not self.nullable
|
|
517
517
|
|
|
518
518
|
@classmethod
|
|
@@ -602,7 +602,7 @@ class TimestampType(ColumnType):
|
|
|
602
602
|
def __init__(self, nullable: bool = False):
|
|
603
603
|
super().__init__(self.Type.TIMESTAMP, nullable=nullable)
|
|
604
604
|
|
|
605
|
-
def has_supertype(self):
|
|
605
|
+
def has_supertype(self) -> bool:
|
|
606
606
|
return not self.nullable
|
|
607
607
|
|
|
608
608
|
@classmethod
|
|
@@ -768,7 +768,7 @@ class JsonType(ColumnType):
|
|
|
768
768
|
a_type = a.get('type')
|
|
769
769
|
b_type = b.get('type')
|
|
770
770
|
|
|
771
|
-
if a_type in
|
|
771
|
+
if a_type in ('string', 'integer', 'number', 'boolean', 'object', 'array') and a_type == b_type:
|
|
772
772
|
# a and b both have the same type designation, but are not identical. This can happen if
|
|
773
773
|
# (for example) they have validators or other attributes that differ. In this case, we
|
|
774
774
|
# generalize to {'type': t}, where t is their shared type, with no other qualifications.
|
|
@@ -1170,6 +1170,20 @@ class DocumentType(ColumnType):
|
|
|
1170
1170
|
XML = 3
|
|
1171
1171
|
TXT = 4
|
|
1172
1172
|
|
|
1173
|
+
@classmethod
|
|
1174
|
+
def from_extension(cls, ext: str) -> Optional['DocumentType.DocumentFormat']:
|
|
1175
|
+
if ext in ('.htm', '.html'):
|
|
1176
|
+
return cls.HTML
|
|
1177
|
+
if ext == '.md':
|
|
1178
|
+
return cls.MD
|
|
1179
|
+
if ext == '.pdf':
|
|
1180
|
+
return cls.PDF
|
|
1181
|
+
if ext == '.xml':
|
|
1182
|
+
return cls.XML
|
|
1183
|
+
if ext == '.txt':
|
|
1184
|
+
return cls.TXT
|
|
1185
|
+
return None
|
|
1186
|
+
|
|
1173
1187
|
def __init__(self, nullable: bool = False, doc_formats: Optional[str] = None):
|
|
1174
1188
|
super().__init__(self.Type.DOCUMENT, nullable=nullable)
|
|
1175
1189
|
self.doc_formats = doc_formats
|
|
@@ -1203,9 +1217,7 @@ class DocumentType(ColumnType):
|
|
|
1203
1217
|
assert isinstance(val, str)
|
|
1204
1218
|
from pixeltable.utils.documents import get_document_handle
|
|
1205
1219
|
|
|
1206
|
-
|
|
1207
|
-
if dh is None:
|
|
1208
|
-
raise excs.Error(f'Not a recognized document format: {val}')
|
|
1220
|
+
_ = get_document_handle(val)
|
|
1209
1221
|
|
|
1210
1222
|
|
|
1211
1223
|
T = typing.TypeVar('T')
|
|
@@ -1240,7 +1252,7 @@ class _PxtType:
|
|
|
1240
1252
|
`ColumnType`.
|
|
1241
1253
|
"""
|
|
1242
1254
|
|
|
1243
|
-
def __init__(self):
|
|
1255
|
+
def __init__(self) -> None:
|
|
1244
1256
|
raise TypeError(f'Type `{type(self)}` cannot be instantiated.')
|
|
1245
1257
|
|
|
1246
1258
|
@classmethod
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import logging
|
|
2
|
+
from typing import TextIO
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
def map_level(verbosity: int) -> int:
|
|
@@ -22,10 +23,10 @@ def map_level(verbosity: int) -> int:
|
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
class ConsoleOutputHandler(logging.StreamHandler):
|
|
25
|
-
def __init__(self, stream):
|
|
26
|
+
def __init__(self, stream: TextIO):
|
|
26
27
|
super().__init__(stream)
|
|
27
28
|
|
|
28
|
-
def emit(self, record):
|
|
29
|
+
def emit(self, record: logging.LogRecord) -> None:
|
|
29
30
|
if record.msg.endswith('\n'):
|
|
30
31
|
self.stream.write(record.msg)
|
|
31
32
|
else:
|