relib 1.0.6__py3-none-any.whl → 1.0.8__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 +1 -0
- relib/measure_duration.py +4 -5
- relib/utils.py +33 -8
- {relib-1.0.6.dist-info → relib-1.0.8.dist-info}/METADATA +1 -1
- relib-1.0.8.dist-info/RECORD +10 -0
- {relib-1.0.6.dist-info → relib-1.0.8.dist-info}/WHEEL +1 -1
- relib-1.0.6.dist-info/RECORD +0 -10
- {relib-1.0.6.dist-info → relib-1.0.8.dist-info}/LICENSE.txt +0 -0
- {relib-1.0.6.dist-info → relib-1.0.8.dist-info}/top_level.txt +0 -0
relib/__init__.py
CHANGED
relib/measure_duration.py
CHANGED
@@ -6,16 +6,15 @@ active_mds = []
|
|
6
6
|
class measure_duration:
|
7
7
|
def __init__(self, name):
|
8
8
|
self.name = name
|
9
|
-
self.start = time()
|
10
9
|
active_mds.append(self)
|
11
10
|
|
12
11
|
def __enter__(self):
|
13
|
-
|
12
|
+
self.start = time()
|
14
13
|
|
15
14
|
def __exit__(self, *_):
|
16
15
|
duration = round(time() - self.start, 4)
|
17
|
-
|
18
|
-
|
16
|
+
depth = len(active_mds) - 1
|
17
|
+
indent = ('──' * depth) + (' ' * (depth > 0))
|
19
18
|
text = '{}: {} seconds'.format(self.name, duration)
|
20
|
-
print(colored(
|
19
|
+
print(colored(indent + text, attrs=['dark']))
|
21
20
|
active_mds.remove(self)
|
relib/utils.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import TypeVar, Union, Iterable, Callable
|
1
|
+
from typing import TypeVar, Union, Iterable, Callable, Any, cast, overload
|
2
2
|
from itertools import chain
|
3
3
|
import numpy as np
|
4
4
|
import re
|
@@ -6,6 +6,11 @@ import re
|
|
6
6
|
T = TypeVar('T')
|
7
7
|
U = TypeVar('U')
|
8
8
|
K = TypeVar('K')
|
9
|
+
K1, K2, K3, K4, K5, K6 = TypeVar('K1'), TypeVar('K2'), TypeVar('K3'), TypeVar('K4'), TypeVar('K5'), TypeVar('K6')
|
10
|
+
|
11
|
+
def non_none(obj: Union[T, None]) -> T:
|
12
|
+
assert obj is not None
|
13
|
+
return obj
|
9
14
|
|
10
15
|
def list_split(l: list[T], sep: T) -> list[list[T]]:
|
11
16
|
l = [sep, *l, sep]
|
@@ -60,10 +65,12 @@ def make_combinations_by_dict(des, keys=None, pairs=[]):
|
|
60
65
|
])
|
61
66
|
|
62
67
|
def merge_dicts(*dicts: dict[K, T]) -> dict[K, T]:
|
63
|
-
|
68
|
+
if len(dicts) == 1:
|
69
|
+
return dicts[0]
|
70
|
+
result = {}
|
64
71
|
for d in dicts:
|
65
|
-
|
66
|
-
return
|
72
|
+
result.update(d)
|
73
|
+
return result
|
67
74
|
|
68
75
|
def intersect(*lists: Iterable[T]) -> list[T]:
|
69
76
|
return list(set.intersection(*map(set, lists)))
|
@@ -102,7 +109,25 @@ def transpose(tuples, default_num_returns=0):
|
|
102
109
|
def map_dict(fn: Callable[[T], U], d: dict[K, T]) -> dict[K, U]:
|
103
110
|
return {key: fn(value) for key, value in d.items()}
|
104
111
|
|
105
|
-
|
112
|
+
@overload
|
113
|
+
def deepen_dict(d: dict[tuple[K1], U]) -> dict[K1, U]: ...
|
114
|
+
|
115
|
+
@overload
|
116
|
+
def deepen_dict(d: dict[tuple[K1, K2], U]) -> dict[K1, dict[K2, U]]: ...
|
117
|
+
|
118
|
+
@overload
|
119
|
+
def deepen_dict(d: dict[tuple[K1, K2, K3], U]) -> dict[K1, dict[K2, dict[K3, U]]]: ...
|
120
|
+
|
121
|
+
@overload
|
122
|
+
def deepen_dict(d: dict[tuple[K1, K2, K3, K4], U]) -> dict[K1, dict[K2, dict[K3, dict[K4, U]]]]: ...
|
123
|
+
|
124
|
+
@overload
|
125
|
+
def deepen_dict(d: dict[tuple[K1, K2, K3, K4, K5], U]) -> dict[K1, dict[K2, dict[K3, dict[K4, dict[K5, U]]]]]: ...
|
126
|
+
|
127
|
+
@overload
|
128
|
+
def deepen_dict(d: dict[tuple[K1, K2, K3, K4, K5, K6], U]) -> dict[K1, dict[K2, dict[K3, dict[K4, dict[K5, dict[K6, U]]]]]]: ...
|
129
|
+
|
130
|
+
def deepen_dict(d: dict[tuple[Any, ...], Any]) -> dict:
|
106
131
|
output = {}
|
107
132
|
for (*tail, head), value in d.items():
|
108
133
|
curr = output
|
@@ -121,13 +146,13 @@ def group(pairs: Iterable[tuple[K, T]]) -> dict[K, list[T]]:
|
|
121
146
|
values_by_key[key].append(value)
|
122
147
|
return values_by_key
|
123
148
|
|
124
|
-
def get_at(d, keys, default):
|
149
|
+
def get_at(d: dict, keys: Iterable[Any], default: T) -> T:
|
125
150
|
try:
|
126
151
|
for key in keys:
|
127
152
|
d = d[key]
|
128
153
|
except KeyError:
|
129
154
|
return default
|
130
|
-
return d
|
155
|
+
return cast(Any, d)
|
131
156
|
|
132
157
|
def sized_partitions(values: Iterable[T], part_size: int) -> list[list[T]]:
|
133
158
|
if not isinstance(values, list):
|
@@ -142,7 +167,7 @@ def num_partitions(values: Iterable[T], num_parts: int) -> list[list[T]]:
|
|
142
167
|
return [values[i * part_size:(i + 1) * part_size] for i in range(num_parts)]
|
143
168
|
|
144
169
|
def _cat_tile(cats, n_tile):
|
145
|
-
|
170
|
+
return cats[np.tile(np.arange(len(cats)), n_tile)]
|
146
171
|
|
147
172
|
def df_from_array(
|
148
173
|
value_cols: dict[str, np.ndarray],
|
@@ -0,0 +1,10 @@
|
|
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=c173SXdFNKC_Mqk5uYBjON1fiQ7yhWB2ebN7AevKgnA,6313
|
6
|
+
relib-1.0.8.dist-info/LICENSE.txt,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
|
7
|
+
relib-1.0.8.dist-info/METADATA,sha256=Uzg6-sdBFSerWr-FpdVnea4o8sysG4ZNnofIqgcl9bw,260
|
8
|
+
relib-1.0.8.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
9
|
+
relib-1.0.8.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
|
10
|
+
relib-1.0.8.dist-info/RECORD,,
|
relib-1.0.6.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
relib/__init__.py,sha256=4yr8xPi3VMbiFlApussB4OXU_U6wzhje06qD0Ad3Gq4,471
|
2
|
-
relib/hashing.py,sha256=6iAPRiJI_4jaSooZRFJnqK2limXqTmErzcwpd050LAA,8943
|
3
|
-
relib/measure_duration.py,sha256=jJa5Kh5FxaBysS__nkwqcnTt8Uc2niLucXfTzFE0j-E,555
|
4
|
-
relib/raypipe.py,sha256=ynEoXs1dnD-360_uQC8v89xjiilt3knpocXpFaQ3plA,1905
|
5
|
-
relib/utils.py,sha256=JM68czDzWLOa2ADbBEdAb7j4Zv3RFYMws5sy0ghxbW0,5353
|
6
|
-
relib-1.0.6.dist-info/LICENSE.txt,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
|
7
|
-
relib-1.0.6.dist-info/METADATA,sha256=NVAMcPbnJrlRd_W8QRuX93F-gHSg47L9dGBf5ap7tnw,260
|
8
|
-
relib-1.0.6.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
9
|
-
relib-1.0.6.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
|
10
|
-
relib-1.0.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|