halib 0.2.29__tar.gz → 0.2.30__tar.gz

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.
Files changed (57) hide show
  1. {halib-0.2.29 → halib-0.2.30}/PKG-INFO +3 -3
  2. {halib-0.2.29 → halib-0.2.30}/README.md +2 -2
  3. {halib-0.2.29 → halib-0.2.30}/halib/utils/dict.py +93 -5
  4. {halib-0.2.29 → halib-0.2.30}/halib.egg-info/PKG-INFO +3 -3
  5. {halib-0.2.29 → halib-0.2.30}/setup.py +1 -1
  6. {halib-0.2.29 → halib-0.2.30}/.gitignore +0 -0
  7. {halib-0.2.29 → halib-0.2.30}/GDriveFolder.txt +0 -0
  8. {halib-0.2.29 → halib-0.2.30}/LICENSE.txt +0 -0
  9. {halib-0.2.29 → halib-0.2.30}/MANIFEST.in +0 -0
  10. {halib-0.2.29 → halib-0.2.30}/halib/__init__.py +0 -0
  11. {halib-0.2.29 → halib-0.2.30}/halib/common/__init__.py +0 -0
  12. {halib-0.2.29 → halib-0.2.30}/halib/common/common.py +0 -0
  13. {halib-0.2.29 → halib-0.2.30}/halib/common/rich_color.py +0 -0
  14. {halib-0.2.29 → halib-0.2.30}/halib/exp/__init__.py +0 -0
  15. {halib-0.2.29 → halib-0.2.30}/halib/exp/core/__init__.py +0 -0
  16. {halib-0.2.29 → halib-0.2.30}/halib/exp/core/base_config.py +0 -0
  17. {halib-0.2.29 → halib-0.2.30}/halib/exp/core/base_exp.py +0 -0
  18. {halib-0.2.29 → halib-0.2.30}/halib/exp/core/param_gen.py +0 -0
  19. {halib-0.2.29 → halib-0.2.30}/halib/exp/core/wandb_op.py +0 -0
  20. {halib-0.2.29 → halib-0.2.30}/halib/exp/data/__init__.py +0 -0
  21. {halib-0.2.29 → halib-0.2.30}/halib/exp/data/dataclass_util.py +0 -0
  22. {halib-0.2.29 → halib-0.2.30}/halib/exp/data/dataset.py +0 -0
  23. {halib-0.2.29 → halib-0.2.30}/halib/exp/data/torchloader.py +0 -0
  24. {halib-0.2.29 → halib-0.2.30}/halib/exp/perf/__init__.py +0 -0
  25. {halib-0.2.29 → halib-0.2.30}/halib/exp/perf/flop_calc.py +0 -0
  26. {halib-0.2.29 → halib-0.2.30}/halib/exp/perf/gpu_mon.py +0 -0
  27. {halib-0.2.29 → halib-0.2.30}/halib/exp/perf/perfcalc.py +0 -0
  28. {halib-0.2.29 → halib-0.2.30}/halib/exp/perf/perfmetrics.py +0 -0
  29. {halib-0.2.29 → halib-0.2.30}/halib/exp/perf/perftb.py +0 -0
  30. {halib-0.2.29 → halib-0.2.30}/halib/exp/perf/profiler.py +0 -0
  31. {halib-0.2.29 → halib-0.2.30}/halib/exp/viz/__init__.py +0 -0
  32. {halib-0.2.29 → halib-0.2.30}/halib/exp/viz/plot.py +0 -0
  33. {halib-0.2.29 → halib-0.2.30}/halib/filetype/__init__.py +0 -0
  34. {halib-0.2.29 → halib-0.2.30}/halib/filetype/csvfile.py +0 -0
  35. {halib-0.2.29 → halib-0.2.30}/halib/filetype/ipynb.py +0 -0
  36. {halib-0.2.29 → halib-0.2.30}/halib/filetype/jsonfile.py +0 -0
  37. {halib-0.2.29 → halib-0.2.30}/halib/filetype/textfile.py +0 -0
  38. {halib-0.2.29 → halib-0.2.30}/halib/filetype/videofile.py +0 -0
  39. {halib-0.2.29 → halib-0.2.30}/halib/filetype/yamlfile.py +0 -0
  40. {halib-0.2.29 → halib-0.2.30}/halib/online/__init__.py +0 -0
  41. {halib-0.2.29 → halib-0.2.30}/halib/online/gdrive.py +0 -0
  42. {halib-0.2.29 → halib-0.2.30}/halib/online/gdrive_mkdir.py +0 -0
  43. {halib-0.2.29 → halib-0.2.30}/halib/online/projectmake.py +0 -0
  44. {halib-0.2.29 → halib-0.2.30}/halib/online/tele_noti.py +0 -0
  45. {halib-0.2.29 → halib-0.2.30}/halib/system/__init__.py +0 -0
  46. {halib-0.2.29 → halib-0.2.30}/halib/system/_list_pc.csv +0 -0
  47. {halib-0.2.29 → halib-0.2.30}/halib/system/cmd.py +0 -0
  48. {halib-0.2.29 → halib-0.2.30}/halib/system/filesys.py +0 -0
  49. {halib-0.2.29 → halib-0.2.30}/halib/system/path.py +0 -0
  50. {halib-0.2.29 → halib-0.2.30}/halib/utils/__init__.py +0 -0
  51. {halib-0.2.29 → halib-0.2.30}/halib/utils/list.py +0 -0
  52. {halib-0.2.29 → halib-0.2.30}/halib/utils/slack.py +0 -0
  53. {halib-0.2.29 → halib-0.2.30}/halib.egg-info/SOURCES.txt +0 -0
  54. {halib-0.2.29 → halib-0.2.30}/halib.egg-info/dependency_links.txt +0 -0
  55. {halib-0.2.29 → halib-0.2.30}/halib.egg-info/requires.txt +0 -0
  56. {halib-0.2.29 → halib-0.2.30}/halib.egg-info/top_level.txt +0 -0
  57. {halib-0.2.29 → halib-0.2.30}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: halib
3
- Version: 0.2.29
3
+ Version: 0.2.30
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -57,11 +57,11 @@ Dynamic: summary
57
57
 
58
58
  ## v0.2.x (Experiment & Core Updates)
59
59
 
60
- ### **v0.2.29**
60
+ ### **v0.2.30**
61
61
 
62
62
  - ✨ **New Feature:**: add `common.common.log_func` as decorator to log function entry, exit, with execution time and arguments.
63
63
 
64
- - 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_remove` and `prune` function
64
+ - 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_exclude/include` and `prune` function
65
65
 
66
66
  ### **v0.2.28**
67
67
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  ## v0.2.x (Experiment & Core Updates)
4
4
 
5
- ### **v0.2.29**
5
+ ### **v0.2.30**
6
6
 
7
7
  - ✨ **New Feature:**: add `common.common.log_func` as decorator to log function entry, exit, with execution time and arguments.
8
8
 
9
- - 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_remove` and `prune` function
9
+ - 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_exclude/include` and `prune` function
10
10
 
11
11
  ### **v0.2.28**
12
12
 
@@ -136,9 +136,9 @@ class DictUtils:
136
136
  return full_hash[:length]
137
137
 
138
138
  @staticmethod
139
- def deep_remove(
139
+ def deep_exclude(
140
140
  d: Dict[str, Any],
141
- keys_to_remove: List[str],
141
+ keys_to_exclude: List[str],
142
142
  in_place: bool = False,
143
143
  sep: str = ".",
144
144
  ) -> Dict[str, Any]:
@@ -147,7 +147,7 @@ class DictUtils:
147
147
 
148
148
  Args:
149
149
  d: The dictionary to filter.
150
- keys_to_remove: A list of flattened keys to remove (e.g., ['model.layers.dropout']).
150
+ keys_to_exclude: A list of flattened keys to exclude (e.g., ['model.layers.dropout']).
151
151
  in_place: If True, modifies the dictionary directly.
152
152
  If False, creates and modifies a deep copy, leaving the original untouched.
153
153
  sep: Separator used in the dot-notation keys (default: ".").
@@ -157,7 +157,7 @@ class DictUtils:
157
157
 
158
158
  Example:
159
159
  >>> data = {'a': {'b': 1, 'c': 2}}
160
- >>> DictUtils.deep_remove(data, ['a.b'], in_place=False)
160
+ >>> DictUtils.deep_exclude(data, ['a.b'], in_place=False)
161
161
  {'a': {'c': 2}}
162
162
  """
163
163
  # 1. Handle the copy logic based on the in_place flag
@@ -167,7 +167,7 @@ class DictUtils:
167
167
  target_dict = copy.deepcopy(d)
168
168
 
169
169
  # 2. Iterate over each dot-notation key we want to delete
170
- for flat_key in keys_to_remove:
170
+ for flat_key in keys_to_exclude:
171
171
  parts = flat_key.split(sep)
172
172
 
173
173
  # 3. Traverse to the parent container of the key we want to delete
@@ -191,6 +191,94 @@ class DictUtils:
191
191
 
192
192
  return target_dict
193
193
 
194
+ @staticmethod
195
+ def deep_include(
196
+ d: Dict[str, Any],
197
+ keys_to_include: List[str],
198
+ in_place: bool = False,
199
+ sep: str = ".",
200
+ ) -> Dict[str, Any]:
201
+ """
202
+ Filters a nested dictionary to keep ONLY the specified dot-notation paths.
203
+
204
+ Args:
205
+ d: The dictionary to filter.
206
+ keys_to_include: A list of flattened keys to include (e.g., ['a.b.c']).
207
+ in_place: If True, modifies the original dictionary.
208
+ sep: Separator used in the dot-notation keys.
209
+
210
+ Returns:
211
+ The filtered dictionary.
212
+ """
213
+ # 1. Create a fresh container for the keys we want to preserve
214
+ # Unlike deep_remove, it's often cleaner to build a new dict
215
+ # than to delete everything else.
216
+ new_dict = {}
217
+
218
+ for flat_key in keys_to_include:
219
+ parts = flat_key.split(sep)
220
+
221
+ # Pointers to traverse both dictionaries
222
+ current_source = d
223
+ current_target = new_dict
224
+
225
+ for i, part in enumerate(parts):
226
+ if isinstance(current_source, dict) and part in current_source:
227
+ # Move down the source
228
+ current_source = current_source[part]
229
+
230
+ # If we are at the leaf of the 'keep' path, copy the value
231
+ if i == len(parts) - 1:
232
+ current_target[part] = copy.deepcopy(current_source)
233
+ else:
234
+ # If the path doesn't exist in our new_dict yet, create it
235
+ if part not in current_target or not isinstance(
236
+ current_target[part], dict
237
+ ):
238
+ current_target[part] = {}
239
+ current_target = current_target[part]
240
+ else:
241
+ # The path to keep doesn't exist in the source, skip it
242
+ break
243
+
244
+ # 2. Handle the in_place logic
245
+ if in_place:
246
+ d.clear()
247
+ d.update(new_dict)
248
+ return d
249
+
250
+ return new_dict
251
+
252
+ @staticmethod
253
+ def apply_exclusion_mask(
254
+ d: Dict[str, Any],
255
+ config_mask: Dict[str, Any],
256
+ in_place: bool = False,
257
+ sep: str = ".",
258
+ ) -> Dict[str, Any]:
259
+ """
260
+ Uses a dictionary 'mask' to define what to throw away.
261
+ """
262
+ # Assuming your DictUtils.flatten returns a dict of {path: value}
263
+ flatten_dict = DictUtils.flatten(config_mask, sep=sep)
264
+ paths_to_exclude = list(flatten_dict.keys())
265
+ return DictUtils.deep_exclude(d, paths_to_exclude, in_place=in_place, sep=sep)
266
+
267
+ @staticmethod
268
+ def apply_inclusion_mask(
269
+ d: Dict[str, Any],
270
+ config_mask: Dict[str, Any],
271
+ in_place: bool = False,
272
+ sep: str = ".",
273
+ ) -> Dict[str, Any]:
274
+ """
275
+ Renamed from 'deep_keep_by_config'.
276
+ Uses a dictionary 'mask' to define what to allow.
277
+ """
278
+ flatten_dict = DictUtils.flatten(config_mask, sep=sep)
279
+ paths_to_include = list(flatten_dict.keys())
280
+ return DictUtils.deep_include(d, paths_to_include, in_place=in_place, sep=sep)
281
+
194
282
  @staticmethod
195
283
  def prune(d: Any, prune_values: Tuple[Any, ...] = (None, {}, [], "")) -> Any:
196
284
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: halib
3
- Version: 0.2.29
3
+ Version: 0.2.30
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -57,11 +57,11 @@ Dynamic: summary
57
57
 
58
58
  ## v0.2.x (Experiment & Core Updates)
59
59
 
60
- ### **v0.2.29**
60
+ ### **v0.2.30**
61
61
 
62
62
  - ✨ **New Feature:**: add `common.common.log_func` as decorator to log function entry, exit, with execution time and arguments.
63
63
 
64
- - 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_remove` and `prune` function
64
+ - 🚀 **Improvement:**: enhance `utils.dict.DictUtils` with `deep_exclude/include` and `prune` function
65
65
 
66
66
  ### **v0.2.28**
67
67
 
@@ -8,7 +8,7 @@ with open("requirements.txt", "r", encoding="utf-8") as f:
8
8
 
9
9
  setuptools.setup(
10
10
  name="halib",
11
- version="0.2.29",
11
+ version="0.2.30",
12
12
  author="Hoang Van Ha",
13
13
  author_email="hoangvanhauit@gmail.com",
14
14
  description="Small library for common tasks",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes