relib 0.2.2__py3-none-any.whl → 0.2.3__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 CHANGED
@@ -1,4 +1,5 @@
1
- from .utils import list_split, drop_none, distinct, find, transpose_dict, make_combinations_by_dict, merge_dicts, intersect, ensure_tuple, omit, tuple_by, flatten, transpose, deepen_dict, group
1
+ from .utils import list_split, drop_none, distinct, find, transpose_dict, make_combinations_by_dict, \
2
+ merge_dicts, intersect, ensure_tuple, omit, dict_by, tuple_by, flatten, transpose, deepen_dict, group
2
3
  from .raypipe import raypipe
3
4
  from .hashing import hash
4
5
  from .measure_duration import measure_duration
relib/utils.py CHANGED
@@ -1,11 +1,9 @@
1
- from typing import TypeVar, Any
2
-
3
- # TODO: make generic for list and set etc (abc.Sequence?)
1
+ from typing import TypeVar, Union, Sequence, Generator, Any
4
2
 
5
3
  T = TypeVar('T')
6
4
  U = TypeVar('U')
7
5
 
8
- def list_split(l: list[T | U], sep: U) -> list[list[T]]:
6
+ def list_split(l: list[T], sep: T) -> list[list[T]]:
9
7
  l = [sep, *l, sep]
10
8
  split_at = [i for i, x in enumerate(l) if x is sep]
11
9
  ranges = list(zip(split_at[0:-1], split_at[1:]))
@@ -15,13 +13,13 @@ def list_split(l: list[T | U], sep: U) -> list[list[T]]:
15
13
  ]
16
14
  return result
17
15
 
18
- def drop_none(l: list[T | None]) -> list[T]:
16
+ def drop_none(l: list[Union[T, None]]) -> list[T]:
19
17
  return [x for x in l if x is not None]
20
18
 
21
19
  def distinct(items: list[T]) -> list[T]:
22
20
  return list(set(items))
23
21
 
24
- def find(iterable):
22
+ def find(iterable: Union[Sequence[T], Generator[T, None, None]]) -> Union[T, None]:
25
23
  return next(iterable, None)
26
24
 
27
25
  def transpose_dict(des):
@@ -53,7 +51,7 @@ def make_combinations_by_dict(des, keys=None, pairs=[]):
53
51
  for pair in new_pairs
54
52
  ])
55
53
 
56
- def merge_dicts(*dicts):
54
+ def merge_dicts(*dicts: dict[T, U]) -> dict[T, U]:
57
55
  result = {}
58
56
  for dictionary in dicts:
59
57
  result.update(dictionary)
@@ -62,28 +60,27 @@ def merge_dicts(*dicts):
62
60
  def intersect(*lists: list[T]) -> list[T]:
63
61
  return set.intersection(*map(set, lists))
64
62
 
65
- # TODO
66
- def ensure_tuple(value):
63
+ def ensure_tuple(value: Union[T, tuple[T, ...]]) -> tuple[T, ...]:
67
64
  if isinstance(value, tuple):
68
65
  return value
69
66
  return (value,)
70
67
 
71
- # TODO
72
- def omit(d, keys):
68
+ def omit(d: dict[T, U], keys: Sequence[T]) -> dict[T, U]:
73
69
  if keys:
74
70
  d = dict(d)
75
71
  for key in keys:
76
72
  del d[key]
77
73
  return d
78
74
 
79
- # TODO
80
- def tuple_by(d, keys):
75
+ def dict_by(keys: Sequence[T], values: Sequence[U]) -> dict[T, U]:
76
+ return dict(zip(keys, values))
77
+
78
+ def tuple_by(d: dict[T, U], keys: Sequence[T]) -> tuple[U, ...]:
81
79
  return tuple(d[key] for key in keys)
82
80
 
83
81
  def flatten(l: list[list[T]]) -> list[T]:
84
82
  return [value for inner_list in l for value in inner_list]
85
83
 
86
- # TODO?
87
84
  def transpose(tuples, default_num_returns=0):
88
85
  result = tuple(zip(*tuples))
89
86
  if not result:
@@ -101,8 +98,7 @@ def deepen_dict(d):
101
98
  curr[head] = value
102
99
  return result
103
100
 
104
- # TODO
105
- def group(pairs):
101
+ def group(pairs: Union[Sequence[tuple[T, U]], Generator[tuple[T, U], None, None]]) -> dict[T, list[U]]:
106
102
  values_by_key = {}
107
103
  for key, value in pairs:
108
104
  if key not in values_by_key:
@@ -1,4 +1,4 @@
1
- Copyright 2018 Hampus Hallman
1
+ Copyright 2023 Hampus Hallman
2
2
 
3
3
  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:
4
4
 
@@ -1,16 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: relib
3
- Version: 0.2.2
4
- Summary: UNKNOWN
3
+ Version: 0.2.3
5
4
  Home-page: https://github.com/Reddan/relib
6
5
  Author: Hampus Hallman
7
6
  Author-email: me@hampushallman.com
8
7
  License: MIT
9
- Platform: UNKNOWN
10
8
  Requires-Python: ~=3.10
11
9
  License-File: LICENSE.txt
12
10
  Requires-Dist: termcolor
13
11
  Requires-Dist: numpy
14
12
 
15
- UNKNOWN
16
-
@@ -0,0 +1,10 @@
1
+ relib/__init__.py,sha256=OmN7DRgA2rYN0XMamE4P3rJPGJIFpnkFQoDXn-GK6sU,309
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=hJ0A3N-H3PaPmT06wWa003FGMlzHMoUOs-Wja49369o,3073
6
+ relib-0.2.3.dist-info/LICENSE.txt,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
7
+ relib-0.2.3.dist-info/METADATA,sha256=9Q6IJAOtehmp-dQR6l3ppMl8MA1-XFJqE5LFSn84Xk4,260
8
+ relib-0.2.3.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
9
+ relib-0.2.3.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
10
+ relib-0.2.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.0)
2
+ Generator: bdist_wheel (0.38.4)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- relib/__init__.py,sha256=njIKwPqhTcHa54Re4rzvDFE-pUz1Txu8aydrshfKB_c,296
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=GVJ1Z1H5kopzEine_lScdqrv4japs3PeYmr2xcWpkgM,2738
6
- relib-0.2.2.dist-info/LICENSE.txt,sha256=2c7g4mni-RUemFGkk6GnoFwknh-leF04BF_J_3gp4sg,1054
7
- relib-0.2.2.dist-info/METADATA,sha256=M_6Cy-pKFcltlw6DI93lwKT520a95yHkHxJUeVz671A,304
8
- relib-0.2.2.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
9
- relib-0.2.2.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
10
- relib-0.2.2.dist-info/RECORD,,