code-loader 1.0.100.dev1__py3-none-any.whl → 1.0.101.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/leaploader.py +7 -11
- code_loader/utils.py +26 -1
- {code_loader-1.0.100.dev1.dist-info → code_loader-1.0.101.dev0.dist-info}/METADATA +1 -1
- {code_loader-1.0.100.dev1.dist-info → code_loader-1.0.101.dev0.dist-info}/RECORD +7 -7
- {code_loader-1.0.100.dev1.dist-info → code_loader-1.0.101.dev0.dist-info}/LICENSE +0 -0
- {code_loader-1.0.100.dev1.dist-info → code_loader-1.0.101.dev0.dist-info}/WHEEL +0 -0
@@ -43,9 +43,6 @@ class PreprocessResponse:
|
|
43
43
|
instance_ids_to_names: Optional[Dict[str, str]] = None # in use only for element instance
|
44
44
|
|
45
45
|
def __post_init__(self) -> None:
|
46
|
-
def is_valid_string(s: str) -> bool:
|
47
|
-
return bool(re.match(r'^[A-Za-z0-9_]+$', s))
|
48
|
-
|
49
46
|
assert self.sample_ids_to_instance_mappings is None, f"Keep sample_ids_to_instance_mappings None when initializing PreprocessResponse"
|
50
47
|
assert self.instance_to_sample_ids_mappings is None, f"Keep instance_to_sample_ids_mappings None when initializing PreprocessResponse"
|
51
48
|
assert self.instance_ids_to_names is None, f"Keep instance_ids_to_names None when initializing PreprocessResponse"
|
@@ -60,8 +57,6 @@ class PreprocessResponse:
|
|
60
57
|
if self.sample_id_type == str:
|
61
58
|
for sample_id in self.sample_ids:
|
62
59
|
assert isinstance(sample_id, str), f"Sample id should be of type str. Got: {type(sample_id)}"
|
63
|
-
if not is_valid_string(sample_id):
|
64
|
-
raise Exception(f"Sample id should contain only letters (A-Z, a-z), numbers or '_'. Got: {sample_id}")
|
65
60
|
else:
|
66
61
|
raise Exception("length is deprecated.")
|
67
62
|
|
code_loader/leaploader.py
CHANGED
@@ -26,7 +26,7 @@ from code_loader.contract.responsedataclasses import DatasetIntegParseResult, Da
|
|
26
26
|
from code_loader.inner_leap_binder import global_leap_binder
|
27
27
|
from code_loader.inner_leap_binder.leapbinder import mapping_runtime_mode_env_var_mame
|
28
28
|
from code_loader.leaploaderbase import LeapLoaderBase
|
29
|
-
from code_loader.utils import get_root_exception_file_and_line_number
|
29
|
+
from code_loader.utils import get_root_exception_file_and_line_number, flatten
|
30
30
|
|
31
31
|
|
32
32
|
class LeapLoader(LeapLoaderBase):
|
@@ -514,22 +514,18 @@ class LeapLoader(LeapLoaderBase):
|
|
514
514
|
|
515
515
|
return converted_value, is_none
|
516
516
|
|
517
|
-
def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[
|
517
|
+
def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[
|
518
|
+
Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
|
518
519
|
result_agg = {}
|
519
520
|
is_none = {}
|
520
521
|
preprocess_result = self._preprocess_result()
|
521
522
|
preprocess_state = preprocess_result[state]
|
522
523
|
for handler in global_leap_binder.setup_container.metadata:
|
523
524
|
handler_result = handler.function(sample_id, preprocess_state)
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
handler_name, single_metadata_result)
|
529
|
-
else:
|
530
|
-
handler_name = handler.name
|
531
|
-
result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
|
532
|
-
handler_name, handler_result)
|
525
|
+
|
526
|
+
for flat_name, flat_result in flatten(handler_result, prefix=handler.name):
|
527
|
+
result_agg[flat_name], is_none[flat_name] = self._convert_metadata_to_correct_type(
|
528
|
+
flat_name, flat_result)
|
533
529
|
|
534
530
|
return result_agg, is_none
|
535
531
|
|
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, Callable
|
4
|
+
from typing import List, Union, Tuple, Any, Iterator, Callable
|
5
5
|
import traceback
|
6
6
|
import numpy as np
|
7
7
|
import numpy.typing as npt
|
@@ -76,3 +76,28 @@ def rescale_min_max(image: npt.NDArray[np.float32]) -> npt.NDArray[np.float32]:
|
|
76
76
|
return image
|
77
77
|
|
78
78
|
|
79
|
+
def flatten(
|
80
|
+
value: Any,
|
81
|
+
*,
|
82
|
+
prefix: str = "",
|
83
|
+
list_token: str = "e",
|
84
|
+
) -> Iterator[Tuple[str, Any]]:
|
85
|
+
"""
|
86
|
+
Recursively walk `value` and yield (flat_key, leaf_value) pairs.
|
87
|
+
|
88
|
+
• Dicts → descend with new_prefix = f"{prefix}_{key}" (or just key if top level)
|
89
|
+
• Sequences → descend with new_prefix = f"{prefix}_{list_token}{idx}"
|
90
|
+
• Leaf scalars → yield the accumulated flat key and the scalar itself
|
91
|
+
"""
|
92
|
+
if isinstance(value, dict):
|
93
|
+
for k, v in value.items():
|
94
|
+
new_prefix = f"{prefix}_{k}" if prefix else k
|
95
|
+
yield from flatten(v, prefix=new_prefix, list_token=list_token)
|
96
|
+
|
97
|
+
elif isinstance(value, (list, tuple)):
|
98
|
+
for idx, v in enumerate(value):
|
99
|
+
new_prefix = f"{prefix}_{list_token}{idx}"
|
100
|
+
yield from flatten(v, prefix=new_prefix, list_token=list_token)
|
101
|
+
|
102
|
+
else: # primitive leaf (str, int, float, bool, None…)
|
103
|
+
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=gJsXu4zVAaiBlq6GJwPxfTD2e0gICTtI_6Ir61MRL48,8838
|
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/mapping.py,sha256=e11h_sprwOyE32PcqgRq9JvyahQrPzwqgkhmbQLKLQY,1165
|
@@ -22,12 +22,12 @@ code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaS
|
|
22
22
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
23
23
|
code_loader/inner_leap_binder/leapbinder.py,sha256=mi9wp98iywHedCe2GwrbiqE14zbGo1rR0huodG96ZXY,32508
|
24
24
|
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=j38nYWfc6yll1SMggV8gABEvSyQwEBVf5RdFnmQ1aD0,38523
|
25
|
-
code_loader/leaploader.py,sha256=
|
25
|
+
code_loader/leaploader.py,sha256=kCNiLdbmGZBo1a6hE1gDRZyOeJLWH2THweO9AtepO3s,28869
|
26
26
|
code_loader/leaploaderbase.py,sha256=lKdw2pd6H9hFsxVmc7jJMoZd_vlG5He1ooqT-cR_yq8,4496
|
27
|
-
code_loader/utils.py,sha256=
|
27
|
+
code_loader/utils.py,sha256=lzisPgCxMo10dn_VFIlkM1fJaYjwaKXgiMB8zZo7oYw,3664
|
28
28
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
29
|
code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
|
30
|
-
code_loader-1.0.
|
31
|
-
code_loader-1.0.
|
32
|
-
code_loader-1.0.
|
33
|
-
code_loader-1.0.
|
30
|
+
code_loader-1.0.101.dev0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
31
|
+
code_loader-1.0.101.dev0.dist-info/METADATA,sha256=XNQDZDS2yCb-da4qiLyq6WM3ymDBp4e9MbNdZJltUBc,855
|
32
|
+
code_loader-1.0.101.dev0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
33
|
+
code_loader-1.0.101.dev0.dist-info/RECORD,,
|
File without changes
|
File without changes
|