code-loader 1.0.84__py3-none-any.whl → 1.0.85a0__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/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[Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
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
- if isinstance(handler_result, dict):
482
- for single_metadata_name, single_metadata_result in handler_result.items():
483
- handler_name = f'{handler.name}_{single_metadata_name}'
484
- result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.84
3
+ Version: 1.0.85a0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -21,12 +21,12 @@ code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaS
21
21
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
22
22
  code_loader/inner_leap_binder/leapbinder.py,sha256=q0nSOOL-yYO4DYZUy4O3sEkzb3SeF1__0POWyZUuh1o,30627
23
23
  code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=qcYyekpIN1hgbmSqTrN7o6IMpfu8ZWp2J_lhMEoV8I8,22598
24
- code_loader/leaploader.py,sha256=QPBG7xrNdzhnOiRtwUlVosyYcFNC_ivWgoS8nWOZ_5M,25768
24
+ code_loader/leaploader.py,sha256=t9ITSzECPg5sGXHxsYkcr45tDipd79hJw6lhwo4yEIE,25412
25
25
  code_loader/leaploaderbase.py,sha256=VH0vddRmkqLtcDlYPCO7hfz1_VbKo43lUdHDAbd4iJc,4198
26
- code_loader/utils.py,sha256=aw2i_fqW_ADjLB66FWZd9DfpCQ7mPdMyauROC5Nd51I,2197
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=Ffx5VHVOe5ujBOsjBSxN_aIEVwFSQ6gbhTMG5aUS-po,2305
29
- code_loader-1.0.84.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
30
- code_loader-1.0.84.dist-info/METADATA,sha256=z_iZ-C_CaFKLmdKX8srTN5LM-unD1Zn-PAPu0MuPCLs,849
31
- code_loader-1.0.84.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
- code_loader-1.0.84.dist-info/RECORD,,
29
+ code_loader-1.0.85a0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
30
+ code_loader-1.0.85a0.dist-info/METADATA,sha256=xSGV70HuiMV5TyqVgUY6efYls57FhAfn3h57aw0KTtc,851
31
+ code_loader-1.0.85a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ code_loader-1.0.85a0.dist-info/RECORD,,