relib 1.0.5__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/__init__.py +2 -1
- relib/utils.py +42 -15
- {relib-1.0.5.dist-info → relib-1.0.7.dist-info}/METADATA +1 -1
- relib-1.0.7.dist-info/RECORD +10 -0
- {relib-1.0.5.dist-info → relib-1.0.7.dist-info}/WHEEL +1 -1
- relib-1.0.5.dist-info/RECORD +0 -10
- {relib-1.0.5.dist-info → relib-1.0.7.dist-info}/LICENSE.txt +0 -0
- {relib-1.0.5.dist-info → relib-1.0.7.dist-info}/top_level.txt +0 -0
relib/__init__.py
CHANGED
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]
|
@@ -22,9 +27,14 @@ def drop_none(l: Iterable[Union[T, None]]) -> list[T]:
|
|
22
27
|
def distinct(items: Iterable[T]) -> list[T]:
|
23
28
|
return list(set(items))
|
24
29
|
|
25
|
-
def
|
30
|
+
def first(iterable: Iterable[T]) -> Union[T, None]:
|
26
31
|
return next(iter(iterable), None)
|
27
32
|
|
33
|
+
def move_value(l: Iterable[T], from_i: int, to_i: int) -> list[T]:
|
34
|
+
l = list(l)
|
35
|
+
l.insert(to_i, l.pop(from_i))
|
36
|
+
return l
|
37
|
+
|
28
38
|
def transpose_dict(des):
|
29
39
|
if isinstance(des, list):
|
30
40
|
keys = list(des[0].keys()) if des else []
|
@@ -55,10 +65,10 @@ def make_combinations_by_dict(des, keys=None, pairs=[]):
|
|
55
65
|
])
|
56
66
|
|
57
67
|
def merge_dicts(*dicts: dict[K, T]) -> dict[K, T]:
|
58
|
-
|
68
|
+
result = {}
|
59
69
|
for d in dicts:
|
60
|
-
|
61
|
-
return
|
70
|
+
result.update(d)
|
71
|
+
return result
|
62
72
|
|
63
73
|
def intersect(*lists: Iterable[T]) -> list[T]:
|
64
74
|
return list(set.intersection(*map(set, lists)))
|
@@ -97,7 +107,25 @@ def transpose(tuples, default_num_returns=0):
|
|
97
107
|
def map_dict(fn: Callable[[T], U], d: dict[K, T]) -> dict[K, U]:
|
98
108
|
return {key: fn(value) for key, value in d.items()}
|
99
109
|
|
100
|
-
|
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:
|
101
129
|
output = {}
|
102
130
|
for (*tail, head), value in d.items():
|
103
131
|
curr = output
|
@@ -116,13 +144,13 @@ def group(pairs: Iterable[tuple[K, T]]) -> dict[K, list[T]]:
|
|
116
144
|
values_by_key[key].append(value)
|
117
145
|
return values_by_key
|
118
146
|
|
119
|
-
def get_at(d, keys, default):
|
147
|
+
def get_at(d: dict, keys: Iterable[Any], default: T) -> T:
|
120
148
|
try:
|
121
149
|
for key in keys:
|
122
150
|
d = d[key]
|
123
151
|
except KeyError:
|
124
152
|
return default
|
125
|
-
return d
|
153
|
+
return cast(Any, d)
|
126
154
|
|
127
155
|
def sized_partitions(values: Iterable[T], part_size: int) -> list[list[T]]:
|
128
156
|
if not isinstance(values, list):
|
@@ -137,7 +165,7 @@ def num_partitions(values: Iterable[T], num_parts: int) -> list[list[T]]:
|
|
137
165
|
return [values[i * part_size:(i + 1) * part_size] for i in range(num_parts)]
|
138
166
|
|
139
167
|
def _cat_tile(cats, n_tile):
|
140
|
-
|
168
|
+
return cats[np.tile(np.arange(len(cats)), n_tile)]
|
141
169
|
|
142
170
|
def df_from_array(
|
143
171
|
value_cols: dict[str, np.ndarray],
|
@@ -148,15 +176,14 @@ def df_from_array(
|
|
148
176
|
dim_names = [name for name, _ in dim_labels]
|
149
177
|
dim_sizes = np.array([len(labels) for _, labels in dim_labels])
|
150
178
|
assert all(array.shape == tuple(dim_sizes) for array in value_cols.values())
|
151
|
-
|
179
|
+
array_offsets = [
|
152
180
|
(dim_sizes[i + 1:].prod(), dim_sizes[:i].prod())
|
153
181
|
for i in range(len(dim_sizes))
|
154
182
|
]
|
155
|
-
|
156
|
-
_cat_tile(pd.Categorical(labels).repeat(repeats), tiles)
|
157
|
-
for labels, (repeats, tiles) in zip(dim_labels,
|
158
|
-
|
159
|
-
category_cols = dict(zip(dim_names, label_arrays))
|
183
|
+
category_cols = {
|
184
|
+
dim: _cat_tile(pd.Categorical(labels).repeat(repeats), tiles)
|
185
|
+
for dim, labels, (repeats, tiles) in zip(dim_names, dim_labels, array_offsets)
|
186
|
+
}
|
160
187
|
value_cols = {name: array.reshape(-1) for name, array in value_cols.items()}
|
161
188
|
df = pd.DataFrame({**category_cols, **value_cols}, copy=False)
|
162
189
|
if indexed:
|
@@ -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.5.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
relib/__init__.py,sha256=Zm6aMrr9A70laX2otqq60JLSO9bLiiwIQQJmk2Qzp_k,456
|
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=Gh_Mb1z8FyzsPAsdCiNLUskztr16ajSrvzQ_lvAn_Tk,5258
|
6
|
-
relib-1.0.5.dist-info/LICENSE.txt,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
|
7
|
-
relib-1.0.5.dist-info/METADATA,sha256=a8d2h8VbXerVegSy2fq3gpWhyHubrfs5UVQKz7Ybqls,260
|
8
|
-
relib-1.0.5.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
9
|
-
relib-1.0.5.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
|
10
|
-
relib-1.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|