relib 1.0.7__py3-none-any.whl → 1.0.9__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 +11 -9
- relib-1.0.9.dist-info/METADATA +16 -0
- relib-1.0.9.dist-info/RECORD +9 -0
- {relib-1.0.7.dist-info → relib-1.0.9.dist-info}/WHEEL +1 -2
- relib-1.0.7.dist-info/METADATA +0 -12
- relib-1.0.7.dist-info/RECORD +0 -10
- relib-1.0.7.dist-info/top_level.txt +0 -1
- /relib-1.0.7.dist-info/LICENSE.txt → /relib-1.0.9.dist-info/licenses/LICENSE +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,
|
1
|
+
from typing import TypeVar, Iterable, Callable, Any, cast, overload
|
2
2
|
from itertools import chain
|
3
3
|
import numpy as np
|
4
4
|
import re
|
@@ -8,7 +8,7 @@ U = TypeVar('U')
|
|
8
8
|
K = TypeVar('K')
|
9
9
|
K1, K2, K3, K4, K5, K6 = TypeVar('K1'), TypeVar('K2'), TypeVar('K3'), TypeVar('K4'), TypeVar('K5'), TypeVar('K6')
|
10
10
|
|
11
|
-
def non_none(obj:
|
11
|
+
def non_none(obj: T | None) -> T:
|
12
12
|
assert obj is not None
|
13
13
|
return obj
|
14
14
|
|
@@ -21,13 +21,13 @@ def list_split(l: list[T], sep: T) -> list[list[T]]:
|
|
21
21
|
for start, end in ranges
|
22
22
|
]
|
23
23
|
|
24
|
-
def drop_none(l: Iterable[
|
24
|
+
def drop_none(l: Iterable[T | None]) -> list[T]:
|
25
25
|
return [x for x in l if x is not None]
|
26
26
|
|
27
27
|
def distinct(items: Iterable[T]) -> list[T]:
|
28
28
|
return list(set(items))
|
29
29
|
|
30
|
-
def first(iterable: Iterable[T]) ->
|
30
|
+
def first(iterable: Iterable[T]) -> T | None:
|
31
31
|
return next(iter(iterable), None)
|
32
32
|
|
33
33
|
def move_value(l: Iterable[T], from_i: int, to_i: int) -> list[T]:
|
@@ -65,6 +65,8 @@ def make_combinations_by_dict(des, keys=None, pairs=[]):
|
|
65
65
|
])
|
66
66
|
|
67
67
|
def merge_dicts(*dicts: dict[K, T]) -> dict[K, T]:
|
68
|
+
if len(dicts) == 1:
|
69
|
+
return dicts[0]
|
68
70
|
result = {}
|
69
71
|
for d in dicts:
|
70
72
|
result.update(d)
|
@@ -73,7 +75,7 @@ def merge_dicts(*dicts: dict[K, T]) -> dict[K, T]:
|
|
73
75
|
def intersect(*lists: Iterable[T]) -> list[T]:
|
74
76
|
return list(set.intersection(*map(set, lists)))
|
75
77
|
|
76
|
-
def ensure_tuple(value:
|
78
|
+
def ensure_tuple(value: T | tuple[T, ...]) -> tuple[T, ...]:
|
77
79
|
return value if isinstance(value, tuple) else (value,)
|
78
80
|
|
79
81
|
def key_of(dicts: Iterable[dict[T, U]], key: T) -> list[U]:
|
@@ -153,6 +155,7 @@ def get_at(d: dict, keys: Iterable[Any], default: T) -> T:
|
|
153
155
|
return cast(Any, d)
|
154
156
|
|
155
157
|
def sized_partitions(values: Iterable[T], part_size: int) -> list[list[T]]:
|
158
|
+
# "chunk"
|
156
159
|
if not isinstance(values, list):
|
157
160
|
values = list(values)
|
158
161
|
num_parts = (len(values) / part_size).__ceil__()
|
@@ -169,11 +172,10 @@ def _cat_tile(cats, n_tile):
|
|
169
172
|
|
170
173
|
def df_from_array(
|
171
174
|
value_cols: dict[str, np.ndarray],
|
172
|
-
dim_labels: list[tuple[str, list[
|
175
|
+
dim_labels: list[tuple[str, list[str | int | float]]],
|
173
176
|
indexed=False,
|
174
177
|
):
|
175
178
|
import pandas as pd
|
176
|
-
dim_names = [name for name, _ in dim_labels]
|
177
179
|
dim_sizes = np.array([len(labels) for _, labels in dim_labels])
|
178
180
|
assert all(array.shape == tuple(dim_sizes) for array in value_cols.values())
|
179
181
|
array_offsets = [
|
@@ -182,12 +184,12 @@ def df_from_array(
|
|
182
184
|
]
|
183
185
|
category_cols = {
|
184
186
|
dim: _cat_tile(pd.Categorical(labels).repeat(repeats), tiles)
|
185
|
-
for dim, labels, (repeats, tiles) in zip(
|
187
|
+
for (dim, labels), (repeats, tiles) in zip(dim_labels, array_offsets)
|
186
188
|
}
|
187
189
|
value_cols = {name: array.reshape(-1) for name, array in value_cols.items()}
|
188
190
|
df = pd.DataFrame({**category_cols, **value_cols}, copy=False)
|
189
191
|
if indexed:
|
190
|
-
df = df.set_index(
|
192
|
+
df = df.set_index([name for name, _ in dim_labels])
|
191
193
|
return df
|
192
194
|
|
193
195
|
StrFilter = Callable[[str], bool]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: relib
|
3
|
+
Version: 1.0.9
|
4
|
+
Project-URL: Repository, https://github.com/Reddan/relib.git
|
5
|
+
Author: Hampus Hallman
|
6
|
+
License: Copyright 2023 Hampus Hallman
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
11
|
+
|
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
|
+
License-File: LICENSE
|
14
|
+
Requires-Python: >=3.12
|
15
|
+
Requires-Dist: numpy>=2.1.0
|
16
|
+
Requires-Dist: termcolor>=2.4.0
|
@@ -0,0 +1,9 @@
|
|
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.0.9.dist-info/METADATA,sha256=nhtMQJqUijL1z2EQWwrP46gRNGFn7TWTdp1psXncw7w,1350
|
7
|
+
relib-1.0.9.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
8
|
+
relib-1.0.9.dist-info/licenses/LICENSE,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
|
9
|
+
relib-1.0.9.dist-info/RECORD,,
|
relib-1.0.7.dist-info/METADATA
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: relib
|
3
|
-
Version: 1.0.7
|
4
|
-
Home-page: https://github.com/Reddan/relib
|
5
|
-
Author: Hampus Hallman
|
6
|
-
Author-email: me@hampushallman.com
|
7
|
-
License: MIT
|
8
|
-
Requires-Python: ~=3.10
|
9
|
-
License-File: LICENSE.txt
|
10
|
-
Requires-Dist: termcolor
|
11
|
-
Requires-Dist: numpy
|
12
|
-
|
relib-1.0.7.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=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,,
|
@@ -1 +0,0 @@
|
|
1
|
-
relib
|
File without changes
|