code-loader 1.0.86__py3-none-any.whl → 1.0.86.dev0__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.
- code_loader/contract/datasetclasses.py +0 -5
- code_loader/inner_leap_binder/leapbinder.py +1 -1
- code_loader/leaploader.py +7 -11
- code_loader/utils.py +26 -1
- {code_loader-1.0.86.dist-info → code_loader-1.0.86.dev0.dist-info}/METADATA +1 -1
- {code_loader-1.0.86.dist-info → code_loader-1.0.86.dev0.dist-info}/RECORD +8 -8
- {code_loader-1.0.86.dist-info → code_loader-1.0.86.dev0.dist-info}/LICENSE +0 -0
- {code_loader-1.0.86.dist-info → code_loader-1.0.86.dev0.dist-info}/WHEEL +0 -0
@@ -40,9 +40,6 @@ class PreprocessResponse:
|
|
40
40
|
sample_id_type: Optional[Union[Type[str], Type[int]]] = None
|
41
41
|
|
42
42
|
def __post_init__(self) -> None:
|
43
|
-
def is_valid_string(s: str) -> bool:
|
44
|
-
return bool(re.match(r'^[A-Za-z0-9_]+$', s))
|
45
|
-
|
46
43
|
if self.length is not None and self.sample_ids is None:
|
47
44
|
self.sample_ids = [i for i in range(self.length)]
|
48
45
|
self.sample_id_type = int
|
@@ -53,8 +50,6 @@ class PreprocessResponse:
|
|
53
50
|
if self.sample_id_type == str:
|
54
51
|
for sample_id in self.sample_ids:
|
55
52
|
assert isinstance(sample_id, str), f"Sample id should be of type str. Got: {type(sample_id)}"
|
56
|
-
if not is_valid_string(sample_id):
|
57
|
-
raise Exception(f"Sample id should contain only letters (A-Z, a-z), numbers or '_'. Got: {sample_id}")
|
58
53
|
else:
|
59
54
|
raise Exception("length is deprecated.")
|
60
55
|
|
@@ -518,7 +518,7 @@ class LeapBinder:
|
|
518
518
|
raise Exception(f"Metadata {single_metadata_name} is None and no metadata type is provided")
|
519
519
|
metadata_type = dataset_base_handler.metadata_type[single_metadata_name]
|
520
520
|
else:
|
521
|
-
raise Exception(f"Metadata {single_metadata_name} is None and
|
521
|
+
raise Exception(f"Metadata {single_metadata_name} is None and metadata type is not a dict")
|
522
522
|
|
523
523
|
result_shape = get_shape(single_metadata_result)
|
524
524
|
metadata_test_result.shape = result_shape
|
code_loader/leaploader.py
CHANGED
@@ -22,7 +22,7 @@ from code_loader.contract.responsedataclasses import DatasetIntegParseResult, Da
|
|
22
22
|
VisualizerInstance, PredictionTypeInstance, ModelSetup, CustomLayerInstance, MetricInstance, CustomLossInstance
|
23
23
|
from code_loader.inner_leap_binder import global_leap_binder
|
24
24
|
from code_loader.leaploaderbase import LeapLoaderBase
|
25
|
-
from code_loader.utils import get_root_exception_file_and_line_number
|
25
|
+
from code_loader.utils import get_root_exception_file_and_line_number, flatten
|
26
26
|
|
27
27
|
|
28
28
|
class LeapLoader(LeapLoaderBase):
|
@@ -471,22 +471,18 @@ class LeapLoader(LeapLoaderBase):
|
|
471
471
|
|
472
472
|
return converted_value, is_none
|
473
473
|
|
474
|
-
def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[
|
474
|
+
def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[
|
475
|
+
Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
|
475
476
|
result_agg = {}
|
476
477
|
is_none = {}
|
477
478
|
preprocess_result = self._preprocess_result()
|
478
479
|
preprocess_state = preprocess_result[state]
|
479
480
|
for handler in global_leap_binder.setup_container.metadata:
|
480
481
|
handler_result = handler.function(sample_id, preprocess_state)
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
handler_name, single_metadata_result)
|
486
|
-
else:
|
487
|
-
handler_name = handler.name
|
488
|
-
result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
|
489
|
-
handler_name, handler_result)
|
482
|
+
|
483
|
+
for flat_name, flat_result in flatten(handler_result, prefix=handler.name):
|
484
|
+
result_agg[flat_name], is_none[flat_name] = self._convert_metadata_to_correct_type(
|
485
|
+
flat_name, flat_result)
|
490
486
|
|
491
487
|
return result_agg, is_none
|
492
488
|
|
code_loader/utils.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import sys
|
2
2
|
from pathlib import Path
|
3
3
|
from types import TracebackType
|
4
|
-
from typing import List, Union, Tuple, Any
|
4
|
+
from typing import List, Union, Tuple, Any, Iterator
|
5
5
|
import traceback
|
6
6
|
import numpy as np
|
7
7
|
import numpy.typing as npt
|
@@ -66,3 +66,28 @@ def rescale_min_max(image: npt.NDArray[np.float32]) -> npt.NDArray[np.float32]:
|
|
66
66
|
return image
|
67
67
|
|
68
68
|
|
69
|
+
def flatten(
|
70
|
+
value: Any,
|
71
|
+
*,
|
72
|
+
prefix: str = "",
|
73
|
+
list_token: str = "e",
|
74
|
+
) -> Iterator[Tuple[str, Any]]:
|
75
|
+
"""
|
76
|
+
Recursively walk `value` and yield (flat_key, leaf_value) pairs.
|
77
|
+
|
78
|
+
• Dicts → descend with new_prefix = f"{prefix}_{key}" (or just key if top level)
|
79
|
+
• Sequences → descend with new_prefix = f"{prefix}_{list_token}{idx}"
|
80
|
+
• Leaf scalars → yield the accumulated flat key and the scalar itself
|
81
|
+
"""
|
82
|
+
if isinstance(value, dict):
|
83
|
+
for k, v in value.items():
|
84
|
+
new_prefix = f"{prefix}_{k}" if prefix else k
|
85
|
+
yield from flatten(v, prefix=new_prefix, list_token=list_token)
|
86
|
+
|
87
|
+
elif isinstance(value, (list, tuple)):
|
88
|
+
for idx, v in enumerate(value):
|
89
|
+
new_prefix = f"{prefix}_{list_token}{idx}"
|
90
|
+
yield from flatten(v, prefix=new_prefix, list_token=list_token)
|
91
|
+
|
92
|
+
else: # primitive leaf (str, int, float, bool, None…)
|
93
|
+
yield prefix, value
|
@@ -1,7 +1,7 @@
|
|
1
1
|
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
2
2
|
code_loader/__init__.py,sha256=6MMWr0ObOU7hkqQKgOqp4Zp3I28L7joGC9iCbQYtAJg,241
|
3
3
|
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
code_loader/contract/datasetclasses.py,sha256=
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=3BWSCHaKtNWlKucMkPKSMiuvZosnnQgXFq2R-GbVOgg,7679
|
5
5
|
code_loader/contract/enums.py,sha256=GEFkvUMXnCNt-GOoz7NJ9ecQZ2PPDettJNOsxsiM0wk,1622
|
6
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
7
7
|
code_loader/contract/responsedataclasses.py,sha256=RSx9m_R3LawhK5o1nAcO3hfp2F9oJYtxZr_bpP3bTmw,4005
|
@@ -19,14 +19,14 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
|
|
19
19
|
code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
|
20
20
|
code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
|
21
21
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
22
|
-
code_loader/inner_leap_binder/leapbinder.py,sha256
|
22
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=-LaQNJ2EVJA7HnxaTJyEYthZgOE7kvaq60OXcDwWgJE,30815
|
23
23
|
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=qcYyekpIN1hgbmSqTrN7o6IMpfu8ZWp2J_lhMEoV8I8,22598
|
24
|
-
code_loader/leaploader.py,sha256=
|
24
|
+
code_loader/leaploader.py,sha256=t9ITSzECPg5sGXHxsYkcr45tDipd79hJw6lhwo4yEIE,25412
|
25
25
|
code_loader/leaploaderbase.py,sha256=VH0vddRmkqLtcDlYPCO7hfz1_VbKo43lUdHDAbd4iJc,4198
|
26
|
-
code_loader/utils.py,sha256=
|
26
|
+
code_loader/utils.py,sha256=4tXLum2AT3Z1ldD6BeYScNg0ATyE4oM8cuIGQxrXyjM,3163
|
27
27
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
28
|
code_loader/visualizers/default_visualizers.py,sha256=f95WzLYO2KU8endWxrmtwjHx7diDfm8AaWjucYHT7GI,2439
|
29
|
-
code_loader-1.0.86.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
30
|
-
code_loader-1.0.86.dist-info/METADATA,sha256=
|
31
|
-
code_loader-1.0.86.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
-
code_loader-1.0.86.dist-info/RECORD,,
|
29
|
+
code_loader-1.0.86.dev0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
30
|
+
code_loader-1.0.86.dev0.dist-info/METADATA,sha256=cF-s4EglKkisMEpQdK5UVTWTuMT7sO06aAPWVY0hPH4,854
|
31
|
+
code_loader-1.0.86.dev0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
+
code_loader-1.0.86.dev0.dist-info/RECORD,,
|
File without changes
|
File without changes
|