relib 1.0.6__py3-none-any.whl → 1.0.7__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/utils.py +31 -8
- {relib-1.0.6.dist-info → relib-1.0.7.dist-info}/METADATA +1 -1
- relib-1.0.7.dist-info/RECORD +10 -0
- {relib-1.0.6.dist-info → relib-1.0.7.dist-info}/WHEEL +1 -1
- relib-1.0.6.dist-info/RECORD +0 -10
- {relib-1.0.6.dist-info → relib-1.0.7.dist-info}/LICENSE.txt +0 -0
- {relib-1.0.6.dist-info → relib-1.0.7.dist-info}/top_level.txt +0 -0
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,10 @@ 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
|
+
result = {}
|
64
69
|
for d in dicts:
|
65
|
-
|
66
|
-
return
|
70
|
+
result.update(d)
|
71
|
+
return result
|
67
72
|
|
68
73
|
def intersect(*lists: Iterable[T]) -> list[T]:
|
69
74
|
return list(set.intersection(*map(set, lists)))
|
@@ -102,7 +107,25 @@ def transpose(tuples, default_num_returns=0):
|
|
102
107
|
def map_dict(fn: Callable[[T], U], d: dict[K, T]) -> dict[K, U]:
|
103
108
|
return {key: fn(value) for key, value in d.items()}
|
104
109
|
|
105
|
-
|
110
|
+
@overload
|
111
|
+
def deepen_dict(d: dict[tuple[K1], U]) -> dict[K1, U]: ...
|
112
|
+
|
113
|
+
@overload
|
114
|
+
def deepen_dict(d: dict[tuple[K1, K2], U]) -> dict[K1, dict[K2, U]]: ...
|
115
|
+
|
116
|
+
@overload
|
117
|
+
def deepen_dict(d: dict[tuple[K1, K2, K3], U]) -> dict[K1, dict[K2, dict[K3, U]]]: ...
|
118
|
+
|
119
|
+
@overload
|
120
|
+
def deepen_dict(d: dict[tuple[K1, K2, K3, K4], U]) -> dict[K1, dict[K2, dict[K3, dict[K4, U]]]]: ...
|
121
|
+
|
122
|
+
@overload
|
123
|
+
def deepen_dict(d: dict[tuple[K1, K2, K3, K4, K5], U]) -> dict[K1, dict[K2, dict[K3, dict[K4, dict[K5, U]]]]]: ...
|
124
|
+
|
125
|
+
@overload
|
126
|
+
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]]]]]]: ...
|
127
|
+
|
128
|
+
def deepen_dict(d: dict[tuple[Any, ...], Any]) -> dict:
|
106
129
|
output = {}
|
107
130
|
for (*tail, head), value in d.items():
|
108
131
|
curr = output
|
@@ -121,13 +144,13 @@ def group(pairs: Iterable[tuple[K, T]]) -> dict[K, list[T]]:
|
|
121
144
|
values_by_key[key].append(value)
|
122
145
|
return values_by_key
|
123
146
|
|
124
|
-
def get_at(d, keys, default):
|
147
|
+
def get_at(d: dict, keys: Iterable[Any], default: T) -> T:
|
125
148
|
try:
|
126
149
|
for key in keys:
|
127
150
|
d = d[key]
|
128
151
|
except KeyError:
|
129
152
|
return default
|
130
|
-
return d
|
153
|
+
return cast(Any, d)
|
131
154
|
|
132
155
|
def sized_partitions(values: Iterable[T], part_size: int) -> list[list[T]]:
|
133
156
|
if not isinstance(values, list):
|
@@ -142,7 +165,7 @@ def num_partitions(values: Iterable[T], num_parts: int) -> list[list[T]]:
|
|
142
165
|
return [values[i * part_size:(i + 1) * part_size] for i in range(num_parts)]
|
143
166
|
|
144
167
|
def _cat_tile(cats, n_tile):
|
145
|
-
|
168
|
+
return cats[np.tile(np.arange(len(cats)), n_tile)]
|
146
169
|
|
147
170
|
def df_from_array(
|
148
171
|
value_cols: dict[str, np.ndarray],
|
@@ -0,0 +1,10 @@
|
|
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=II0PikMmpc9Ds2F3jPRXuIFD5RTUk7Bk2-8C4gvL0T8,6271
|
6
|
+
relib-1.0.7.dist-info/LICENSE.txt,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
|
7
|
+
relib-1.0.7.dist-info/METADATA,sha256=Lax2ex1ap8pZJrXzKA4Dc5qnSBt2FqHOS5XK51WJNQQ,260
|
8
|
+
relib-1.0.7.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
9
|
+
relib-1.0.7.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
|
10
|
+
relib-1.0.7.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
|