code-loader 1.0.96__py3-none-any.whl → 1.0.97.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.
Potentially problematic release.
This version of code-loader might be problematic. Click here for more details.
- code_loader/contract/datasetclasses.py +0 -5
- code_loader/leaploader.py +7 -11
- code_loader/utils.py +26 -1
- {code_loader-1.0.96.dist-info → code_loader-1.0.97.dev0.dist-info}/METADATA +1 -1
- {code_loader-1.0.96.dist-info → code_loader-1.0.97.dev0.dist-info}/RECORD +7 -7
- {code_loader-1.0.96.dist-info → code_loader-1.0.97.dev0.dist-info}/LICENSE +0 -0
- {code_loader-1.0.96.dist-info → code_loader-1.0.97.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
|
|
code_loader/leaploader.py
CHANGED
|
@@ -23,7 +23,7 @@ from code_loader.contract.responsedataclasses import DatasetIntegParseResult, Da
|
|
|
23
23
|
EngineFileContract
|
|
24
24
|
from code_loader.inner_leap_binder import global_leap_binder
|
|
25
25
|
from code_loader.leaploaderbase import LeapLoaderBase
|
|
26
|
-
from code_loader.utils import get_root_exception_file_and_line_number
|
|
26
|
+
from code_loader.utils import get_root_exception_file_and_line_number, flatten
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
class LeapLoader(LeapLoaderBase):
|
|
@@ -477,22 +477,18 @@ class LeapLoader(LeapLoaderBase):
|
|
|
477
477
|
|
|
478
478
|
return converted_value, is_none
|
|
479
479
|
|
|
480
|
-
def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[
|
|
480
|
+
def _get_metadata(self, state: DataStateEnum, sample_id: Union[int, str]) -> Tuple[
|
|
481
|
+
Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
|
|
481
482
|
result_agg = {}
|
|
482
483
|
is_none = {}
|
|
483
484
|
preprocess_result = self._preprocess_result()
|
|
484
485
|
preprocess_state = preprocess_result[state]
|
|
485
486
|
for handler in global_leap_binder.setup_container.metadata:
|
|
486
487
|
handler_result = handler.function(sample_id, preprocess_state)
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
handler_name, single_metadata_result)
|
|
492
|
-
else:
|
|
493
|
-
handler_name = handler.name
|
|
494
|
-
result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
|
|
495
|
-
handler_name, handler_result)
|
|
488
|
+
|
|
489
|
+
for flat_name, flat_result in flatten(handler_result, prefix=handler.name):
|
|
490
|
+
result_agg[flat_name], is_none[flat_name] = self._convert_metadata_to_correct_type(
|
|
491
|
+
flat_name, flat_result)
|
|
496
492
|
|
|
497
493
|
return result_agg, is_none
|
|
498
494
|
|
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/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=Acg5C8pMlQHSCTNmTXlMiLdS7P_k6sBUahD5ffr6mN4,31794
|
|
24
24
|
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=y5TuhJe-J3xEE0Oj7bxIfhyN1lXiLJgfgy3ZiAs-yic,24364
|
|
25
|
-
code_loader/leaploader.py,sha256=
|
|
25
|
+
code_loader/leaploader.py,sha256=qUV-MmxZzESxi8zciKiitGObgks_5d58tgrZyJwRpuU,26125
|
|
26
26
|
code_loader/leaploaderbase.py,sha256=VH0vddRmkqLtcDlYPCO7hfz1_VbKo43lUdHDAbd4iJc,4198
|
|
27
|
-
code_loader/utils.py,sha256=
|
|
27
|
+
code_loader/utils.py,sha256=4tXLum2AT3Z1ldD6BeYScNg0ATyE4oM8cuIGQxrXyjM,3163
|
|
28
28
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
29
|
code_loader/visualizers/default_visualizers.py,sha256=669lBpLISLO6my5Qcgn1FLDDeZgHumPf252m4KHY4YM,2555
|
|
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.97.dev0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
31
|
+
code_loader-1.0.97.dev0.dist-info/METADATA,sha256=VjlJJJzJiQXZgcE2dzItxMz4B2mrry2W3GSEK_YkFyk,854
|
|
32
|
+
code_loader-1.0.97.dev0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
33
|
+
code_loader-1.0.97.dev0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|