relib 1.1.0__py3-none-any.whl → 1.1.2__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.
relib/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from .utils import (
2
+ clear_console,
2
3
  non_none,
3
4
  list_split,
4
5
  drop_none,
@@ -19,7 +20,11 @@ from .utils import (
19
20
  transpose,
20
21
  map_dict,
21
22
  deepen_dict,
23
+ flatten_dict_inner,
24
+ flatten_dict,
22
25
  group,
26
+ reversed_enumerate,
27
+ get_at,
23
28
  sized_partitions,
24
29
  num_partitions,
25
30
  df_from_array,
relib/utils.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from typing import TypeVar, Iterable, Callable, Any, cast, overload
2
2
  from itertools import chain
3
3
  import numpy as np
4
+ import os
4
5
  import re
5
6
 
6
7
  T = TypeVar('T')
@@ -8,6 +9,9 @@ U = TypeVar('U')
8
9
  K = TypeVar('K')
9
10
  K1, K2, K3, K4, K5, K6 = TypeVar('K1'), TypeVar('K2'), TypeVar('K3'), TypeVar('K4'), TypeVar('K5'), TypeVar('K6')
10
11
 
12
+ def clear_console():
13
+ os.system("cls" if os.name == "nt" else "clear")
14
+
11
15
  def non_none(obj: T | None) -> T:
12
16
  assert obj is not None
13
17
  return obj
@@ -129,23 +133,34 @@ def deepen_dict(d: dict[tuple[K1, K2, K3, K4, K5, K6], U]) -> dict[K1, dict[K2,
129
133
 
130
134
  def deepen_dict(d: dict[tuple[Any, ...], Any]) -> dict:
131
135
  output = {}
136
+ if () in d:
137
+ return d[()]
132
138
  for (*tail, head), value in d.items():
133
139
  curr = output
134
140
  for key in tail:
135
- if key not in curr:
136
- curr[key] = {}
137
- curr = curr[key]
141
+ curr = curr.setdefault(key, {})
138
142
  curr[head] = value
139
143
  return output
140
144
 
145
+ def flatten_dict_inner(d, prefix=()):
146
+ for key, value in d.items():
147
+ if not isinstance(value, dict) or value == {}:
148
+ yield prefix + (key,), value
149
+ else:
150
+ yield from flatten_dict_inner(value, prefix + (key,))
151
+
152
+ def flatten_dict(deep_dict: dict, prefix=()) -> dict:
153
+ return dict(flatten_dict_inner(deep_dict, prefix))
154
+
141
155
  def group(pairs: Iterable[tuple[K, T]]) -> dict[K, list[T]]:
142
156
  values_by_key = {}
143
157
  for key, value in pairs:
144
- if key not in values_by_key:
145
- values_by_key[key] = []
146
- values_by_key[key].append(value)
158
+ values_by_key.setdefault(key, []).append(value)
147
159
  return values_by_key
148
160
 
161
+ def reversed_enumerate(l: list[T] | tuple[T, ...]) -> Iterable[tuple[int, T]]:
162
+ return zip(reversed(range(len(l))), reversed(l))
163
+
149
164
  def get_at(d: dict, keys: Iterable[Any], default: T) -> T:
150
165
  try:
151
166
  for key in keys:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: relib
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Project-URL: Repository, https://github.com/Reddan/relib.git
5
5
  Author: Hampus Hallman
6
6
  License: Copyright 2023 Hampus Hallman
@@ -12,5 +12,5 @@ License: Copyright 2023 Hampus Hallman
12
12
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
13
  License-File: LICENSE
14
14
  Requires-Python: >=3.12
15
- Requires-Dist: numpy>=2.1.0
16
- Requires-Dist: termcolor>=2.4.0
15
+ Requires-Dist: numpy
16
+ Requires-Dist: termcolor
@@ -0,0 +1,9 @@
1
+ relib/__init__.py,sha256=j1aTW1Xm9U5DlkHVR_1-k80TEZSClojoRNb_fa4rkuQ,570
2
+ relib/hashing.py,sha256=6iAPRiJI_4jaSooZRFJnqK2limXqTmErzcwpd050LAA,8943
3
+ relib/measure_duration.py,sha256=mTFvqGxKN2vTuHXEaWGHqZ-zm68Gbynxt1u6BHzKEQ8,511
4
+ relib/raypipe.py,sha256=ynEoXs1dnD-360_uQC8v89xjiilt3knpocXpFaQ3plA,1905
5
+ relib/utils.py,sha256=WezIji5azJ5A6SsWjYeUCRZApi-a1CVtDqfRaAVhWu4,6753
6
+ relib-1.1.2.dist-info/METADATA,sha256=x3I9Pn8wm7EGEF7YVtxb0eLqzf_AIHaS9kqYrJtdW2k,1336
7
+ relib-1.1.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
8
+ relib-1.1.2.dist-info/licenses/LICENSE,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
9
+ relib-1.1.2.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- relib/__init__.py,sha256=nz5c2tIomUVXKzQshrt4s9dS_HirItWNa9Aem-9q368,483
2
- relib/hashing.py,sha256=6iAPRiJI_4jaSooZRFJnqK2limXqTmErzcwpd050LAA,8943
3
- relib/measure_duration.py,sha256=mTFvqGxKN2vTuHXEaWGHqZ-zm68Gbynxt1u6BHzKEQ8,511
4
- relib/raypipe.py,sha256=ynEoXs1dnD-360_uQC8v89xjiilt3knpocXpFaQ3plA,1905
5
- relib/utils.py,sha256=h_5UMOuXG4u6haslL88ESPKIBfBFhUvdobzo3eIrQs8,6256
6
- relib-1.1.0.dist-info/METADATA,sha256=tUzWlM435PKTI5sAiOYzgcw_1Im1nYwXFpa_sgR2Dx0,1350
7
- relib-1.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
8
- relib-1.1.0.dist-info/licenses/LICENSE,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
9
- relib-1.1.0.dist-info/RECORD,,
File without changes