code-loader 1.0.92.dev5__py3-none-any.whl → 1.0.93.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.

@@ -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
 
@@ -121,23 +121,19 @@ class LeapGraph:
121
121
  x_label = 'Frequency [Seconds]'
122
122
  y_label = 'Amplitude [Voltage]'
123
123
  x_range = (0.1, 3.0)
124
- legend = ['experiment1', 'experiment2', 'experiment3']
125
- leap_graph = LeapGraph(data=graph_data, x_label=x_label, y_label=y_label, x_range=x_range, legend=legend)
124
+ leap_graph = LeapGraph(data=graph_data, x_label=x_label, y_label=y_label, x_range=x_range)
126
125
  """
127
126
  data: npt.NDArray[np.float32]
128
127
  type: LeapDataType = LeapDataType.Graph
129
128
  x_label: Optional[str] = None
130
129
  y_label: Optional[str] = None
131
130
  x_range: Optional[Tuple[float,float]] = None
132
- legend: Optional[List[str]] = None
133
131
 
134
132
  def __post_init__(self) -> None:
135
133
  validate_type(self.type, LeapDataType.Graph)
136
134
  validate_type(type(self.data), np.ndarray)
137
135
  validate_type(self.data.dtype, np.float32)
138
- validate_type(len(self.data.shape), 2, f'Graph must be of shape 2')
139
- if self.legend:
140
- validate_type(self.data.shape[1], len(self.legend), 'Number of labels supplied should equal the number of graphs')
136
+ validate_type(len(self.data.shape), 2, 'Graph must be of shape 2')
141
137
  validate_type(type(self.x_label), [str, type(None)], 'x_label must be a string or None')
142
138
  validate_type(type(self.y_label), [str, type(None)], 'y_label must be a string or None')
143
139
  validate_type(type(self.x_range), [tuple, type(None)], 'x_range must be a tuple or None')
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[Dict[str, Union[str, int, bool, float]], Dict[str, bool]]:
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
- if isinstance(handler_result, dict):
488
- for single_metadata_name, single_metadata_result in handler_result.items():
489
- handler_name = f'{handler.name}_{single_metadata_name}'
490
- result_agg[handler_name], is_none[handler_name] = self._convert_metadata_to_correct_type(
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
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 TensorLeap
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,7 +1,8 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.92.dev5
3
+ Version: 1.0.93.dev0
4
4
  Summary:
5
+ Home-page: https://github.com/tensorleap/code-loader
5
6
  License: MIT
6
7
  Author: dorhar
7
8
  Author-email: doron.harnoy@tensorleap.ai
@@ -16,7 +17,6 @@ Requires-Dist: numpy (>=1.22.3,<2.0.0)
16
17
  Requires-Dist: psutil (>=5.9.5,<6.0.0)
17
18
  Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
18
19
  Requires-Dist: requests (>=2.32.3,<3.0.0)
19
- Project-URL: Homepage, https://github.com/tensorleap/code-loader
20
20
  Project-URL: Repository, https://github.com/tensorleap/code-loader
21
21
  Description-Content-Type: text/markdown
22
22
 
@@ -1,11 +1,12 @@
1
+ LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
1
2
  code_loader/__init__.py,sha256=6MMWr0ObOU7hkqQKgOqp4Zp3I28L7joGC9iCbQYtAJg,241
2
3
  code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- code_loader/contract/datasetclasses.py,sha256=ZN6XC-tg0qaT-GF4YiV2SsM2dUQW4fc1akLF-J4YT0w,7964
4
+ code_loader/contract/datasetclasses.py,sha256=3BWSCHaKtNWlKucMkPKSMiuvZosnnQgXFq2R-GbVOgg,7679
4
5
  code_loader/contract/enums.py,sha256=GEFkvUMXnCNt-GOoz7NJ9ecQZ2PPDettJNOsxsiM0wk,1622
5
6
  code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
6
7
  code_loader/contract/mapping.py,sha256=e11h_sprwOyE32PcqgRq9JvyahQrPzwqgkhmbQLKLQY,1165
7
8
  code_loader/contract/responsedataclasses.py,sha256=6-5DJkYBdXb3UB1eNidTTPPBIYxMjEoMdYDkp9VhH8o,4223
8
- code_loader/contract/visualizer_classes.py,sha256=Wz9eItmoRaKEHa3p0aW0Ypxx4_xUmaZyLBznnTuxwi0,15425
9
+ code_loader/contract/visualizer_classes.py,sha256=_nlukRfW8QeQaQG7G5HfAUSeCuoqslB4xJS2AGI_Nz8,15156
9
10
  code_loader/default_losses.py,sha256=NoOQym1106bDN5dcIk56Elr7ZG5quUHArqfP5-Nyxyo,1139
10
11
  code_loader/default_metrics.py,sha256=v16Mrt2Ze1tXPgfKywGVdRSrkaK4CKLNQztN1UdVqIY,5010
11
12
  code_loader/experiment_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -21,12 +22,12 @@ code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaS
21
22
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
22
23
  code_loader/inner_leap_binder/leapbinder.py,sha256=mRg5ofWNbUkRsIafaz7i7NKi-1USgeAuNTIBxASSMcw,31713
23
24
  code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=y5TuhJe-J3xEE0Oj7bxIfhyN1lXiLJgfgy3ZiAs-yic,24364
24
- code_loader/leaploader.py,sha256=GGHZzovqGsM6oY14pwyL35LeOmdRfjVuhhY2ZqlYKaM,26481
25
+ code_loader/leaploader.py,sha256=qUV-MmxZzESxi8zciKiitGObgks_5d58tgrZyJwRpuU,26125
25
26
  code_loader/leaploaderbase.py,sha256=VH0vddRmkqLtcDlYPCO7hfz1_VbKo43lUdHDAbd4iJc,4198
26
- code_loader/utils.py,sha256=aw2i_fqW_ADjLB66FWZd9DfpCQ7mPdMyauROC5Nd51I,2197
27
+ code_loader/utils.py,sha256=4tXLum2AT3Z1ldD6BeYScNg0ATyE4oM8cuIGQxrXyjM,3163
27
28
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
29
  code_loader/visualizers/default_visualizers.py,sha256=669lBpLISLO6my5Qcgn1FLDDeZgHumPf252m4KHY4YM,2555
29
- code_loader-1.0.92.dev5.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
30
- code_loader-1.0.92.dev5.dist-info/METADATA,sha256=ZOd799qKAukBP4bdouok8Brvc-KTNm3XgqZ2qcwn8Jw,866
31
- code_loader-1.0.92.dev5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
32
- code_loader-1.0.92.dev5.dist-info/RECORD,,
30
+ code_loader-1.0.93.dev0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
31
+ code_loader-1.0.93.dev0.dist-info/METADATA,sha256=0J3gHZjOA70xw29bZLKPu_dvxV3Qo6OHUPmbjPYW8wc,854
32
+ code_loader-1.0.93.dev0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
33
+ code_loader-1.0.93.dev0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
File without changes