relib 1.0.8__py3-none-any.whl → 1.1.0__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 CHANGED
@@ -1,4 +1,4 @@
1
- from typing import TypeVar, Union, Iterable, Callable, Any, cast, overload
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: Union[T, None]) -> T:
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[Union[T, None]]) -> list[T]:
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]) -> Union[T, None]:
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]:
@@ -75,7 +75,7 @@ def merge_dicts(*dicts: dict[K, T]) -> dict[K, T]:
75
75
  def intersect(*lists: Iterable[T]) -> list[T]:
76
76
  return list(set.intersection(*map(set, lists)))
77
77
 
78
- def ensure_tuple(value: Union[T, tuple[T, ...]]) -> tuple[T, ...]:
78
+ def ensure_tuple(value: T | tuple[T, ...]) -> tuple[T, ...]:
79
79
  return value if isinstance(value, tuple) else (value,)
80
80
 
81
81
  def key_of(dicts: Iterable[dict[T, U]], key: T) -> list[U]:
@@ -155,6 +155,7 @@ def get_at(d: dict, keys: Iterable[Any], default: T) -> T:
155
155
  return cast(Any, d)
156
156
 
157
157
  def sized_partitions(values: Iterable[T], part_size: int) -> list[list[T]]:
158
+ # "chunk"
158
159
  if not isinstance(values, list):
159
160
  values = list(values)
160
161
  num_parts = (len(values) / part_size).__ceil__()
@@ -171,11 +172,10 @@ def _cat_tile(cats, n_tile):
171
172
 
172
173
  def df_from_array(
173
174
  value_cols: dict[str, np.ndarray],
174
- dim_labels: list[tuple[str, list[Union[str, int, float]]]],
175
+ dim_labels: list[tuple[str, list[str | int | float]]],
175
176
  indexed=False,
176
177
  ):
177
178
  import pandas as pd
178
- dim_names = [name for name, _ in dim_labels]
179
179
  dim_sizes = np.array([len(labels) for _, labels in dim_labels])
180
180
  assert all(array.shape == tuple(dim_sizes) for array in value_cols.values())
181
181
  array_offsets = [
@@ -184,12 +184,12 @@ def df_from_array(
184
184
  ]
185
185
  category_cols = {
186
186
  dim: _cat_tile(pd.Categorical(labels).repeat(repeats), tiles)
187
- for dim, labels, (repeats, tiles) in zip(dim_names, dim_labels, array_offsets)
187
+ for (dim, labels), (repeats, tiles) in zip(dim_labels, array_offsets)
188
188
  }
189
189
  value_cols = {name: array.reshape(-1) for name, array in value_cols.items()}
190
190
  df = pd.DataFrame({**category_cols, **value_cols}, copy=False)
191
191
  if indexed:
192
- df = df.set_index(dim_names)
192
+ df = df.set_index([name for name, _ in dim_labels])
193
193
  return df
194
194
 
195
195
  StrFilter = Callable[[str], bool]
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.3
2
+ Name: relib
3
+ Version: 1.1.0
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.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,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.2.0)
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -1,12 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: relib
3
- Version: 1.0.8
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
-
@@ -1,10 +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=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,,
@@ -1 +0,0 @@
1
- relib