dycw-utilities 0.124.0__py3-none-any.whl → 0.125.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.
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.124.0
3
+ Version: 0.125.0
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
7
7
  Requires-Dist: typing-extensions<4.14,>=4.13.1
8
8
  Provides-Extra: test
9
- Requires-Dist: hypothesis<6.132,>=6.131.21; extra == 'test'
9
+ Requires-Dist: hypothesis<6.132,>=6.131.24; extra == 'test'
10
10
  Requires-Dist: pytest-asyncio<0.27,>=0.26.0; extra == 'test'
11
11
  Requires-Dist: pytest-cov<6.2,>=6.1.1; extra == 'test'
12
12
  Requires-Dist: pytest-instafail<0.6,>=0.5.0; extra == 'test'
@@ -27,8 +27,6 @@ Requires-Dist: img2pdf<0.7,>=0.6.0; extra == 'zzz-test-altair'
27
27
  Requires-Dist: polars-lts-cpu<1.31,>=1.30.0; extra == 'zzz-test-altair'
28
28
  Requires-Dist: vl-convert-python<1.8,>=1.7.0; extra == 'zzz-test-altair'
29
29
  Requires-Dist: whenever<0.9,>=0.8.2; extra == 'zzz-test-altair'
30
- Provides-Extra: zzz-test-astor
31
- Requires-Dist: astor<0.9,>=0.8.1; extra == 'zzz-test-astor'
32
30
  Provides-Extra: zzz-test-asyncio
33
31
  Provides-Extra: zzz-test-atomicwrites
34
32
  Requires-Dist: atomicwrites<1.5,>=1.4.1; extra == 'zzz-test-atomicwrites'
@@ -80,7 +78,7 @@ Provides-Extra: zzz-test-hypothesis
80
78
  Requires-Dist: aiosqlite<0.22,>=0.21.0; extra == 'zzz-test-hypothesis'
81
79
  Requires-Dist: asyncpg<0.31,>=0.30.0; extra == 'zzz-test-hypothesis'
82
80
  Requires-Dist: greenlet<3.3,>=3.2.0; extra == 'zzz-test-hypothesis'
83
- Requires-Dist: hypothesis<6.132,>=6.131.21; extra == 'zzz-test-hypothesis'
81
+ Requires-Dist: hypothesis<6.132,>=6.131.24; extra == 'zzz-test-hypothesis'
84
82
  Requires-Dist: luigi<3.7,>=3.6.0; extra == 'zzz-test-hypothesis'
85
83
  Requires-Dist: numpy<2.3,>=2.2.6; extra == 'zzz-test-hypothesis'
86
84
  Requires-Dist: pathvalidate<3.3,>=3.2.3; extra == 'zzz-test-hypothesis'
@@ -1,6 +1,5 @@
1
- utilities/__init__.py,sha256=HeZfuK-rk7XFCrcSKl_fSwvax77ZgizR9BO2AjEIbLs,60
1
+ utilities/__init__.py,sha256=QGDJ0f72zDhkWMU5d6JojuaUWYcF1Z-mqiuQN6pmnBo,60
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
- utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
4
3
  utilities/asyncio.py,sha256=joGmwv-WiDLYoK4q41TtVgfIT23s8Ok46jT_yEQGjaM,28240
5
4
  utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
6
5
  utilities/atools.py,sha256=IYMuFSFGSKyuQmqD6v5IUtDlz8PPw0Sr87Cub_gRU3M,1168
@@ -36,7 +35,7 @@ utilities/luigi.py,sha256=fpH9MbxJDuo6-k9iCXRayFRtiVbUtibCJKugf7ygpv0,5988
36
35
  utilities/math.py,sha256=-mQgbah-dPJwOEWf3SonrFoVZ2AVxMgpeQ3dfVa-oJA,26764
37
36
  utilities/memory_profiler.py,sha256=tf2C51P2lCujPGvRt2Rfc7VEw5LDXmVPCG3z_AvBmbU,962
38
37
  utilities/modules.py,sha256=iuvLluJya-hvl1Q25-Jk3dLgx2Es3ck4SjJiEkAlVTs,3195
39
- utilities/more_itertools.py,sha256=6T0225gBFZtv47-B0JRFOKMz836Wg3Hct79ePPLGpuo,5827
38
+ utilities/more_itertools.py,sha256=fYsGyIPB2s1KRWoH3AkV3CxJxnMLvmidqBf8l1VQnyE,7193
40
39
  utilities/numpy.py,sha256=Xn23sA2ZbVNqwUYEgNJD3XBYH6IbCri_WkHSNhg3NkY,26122
41
40
  utilities/operator.py,sha256=0M2yZJ0PODH47ogFEnkGMBe_cfxwZR02T_92LZVZvHo,3715
42
41
  utilities/optuna.py,sha256=loyJGWTzljgdJaoLhP09PT8Jz6o_pwBOwehY33lHkhw,1923
@@ -88,7 +87,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
88
87
  utilities/whenever.py,sha256=jS31ZAY5OMxFxLja_Yo5Fidi87Pd-GoVZ7Vi_teqVDA,16743
89
88
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
90
89
  utilities/zoneinfo.py,sha256=-5j7IQ9nb7gR43rdgA7ms05im-XuqhAk9EJnQBXxCoQ,1874
91
- dycw_utilities-0.124.0.dist-info/METADATA,sha256=-1BZhlwOBb6JkkxdOqznS-XXxhlcvdZfGawiKrjB7Fc,12943
92
- dycw_utilities-0.124.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
- dycw_utilities-0.124.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
94
- dycw_utilities-0.124.0.dist-info/RECORD,,
90
+ dycw_utilities-0.125.0.dist-info/METADATA,sha256=539k9z6K4GTl6bfPw8x0gEN_tWp0guvq15SQrIcaHjg,12852
91
+ dycw_utilities-0.125.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
+ dycw_utilities-0.125.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
93
+ dycw_utilities-0.125.0.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.124.0"
3
+ __version__ = "0.125.0"
@@ -37,25 +37,81 @@ _U = TypeVar("_U")
37
37
 
38
38
  @overload
39
39
  def bucket_mapping(
40
- iterable: Iterable[_T], func: Callable[[_T], THashable], /, *, list: Literal[True]
40
+ iterable: Iterable[_T],
41
+ func: Callable[[_T], THashable],
42
+ /,
43
+ *,
44
+ transform: Callable[[_T], _U],
45
+ list: Literal[True],
46
+ ) -> Mapping[THashable, Sequence[_U]]: ...
47
+ @overload
48
+ def bucket_mapping(
49
+ iterable: Iterable[_T],
50
+ func: Callable[[_T], THashable],
51
+ /,
52
+ *,
53
+ transform: Callable[[_T], _U],
54
+ list: bool = False,
55
+ ) -> Mapping[THashable, Iterator[_U]]: ...
56
+ @overload
57
+ def bucket_mapping(
58
+ iterable: Iterable[_T],
59
+ func: Callable[[_T], THashable],
60
+ /,
61
+ *,
62
+ transform: Callable[[_T], _U] | None = None,
63
+ list: Literal[True],
41
64
  ) -> Mapping[THashable, Sequence[_T]]: ...
42
65
  @overload
43
66
  def bucket_mapping(
44
- iterable: Iterable[_T], func: Callable[[_T], THashable], /, *, list: bool = False
67
+ iterable: Iterable[_T],
68
+ func: Callable[[_T], THashable],
69
+ /,
70
+ *,
71
+ transform: Callable[[_T], _U] | None = None,
72
+ list: bool = False,
45
73
  ) -> Mapping[THashable, Iterator[_T]]: ...
74
+ @overload
75
+ def bucket_mapping(
76
+ iterable: Iterable[_T],
77
+ func: Callable[[_T], THashable],
78
+ /,
79
+ *,
80
+ transform: Callable[[_T], _U] | None = None,
81
+ list: bool = False,
82
+ ) -> (
83
+ Mapping[THashable, Iterator[_T]]
84
+ | Mapping[THashable, Iterator[_U]]
85
+ | Mapping[THashable, Sequence[_T]]
86
+ | Mapping[THashable, Sequence[_U]]
87
+ ): ...
46
88
  def bucket_mapping(
47
89
  iterable: Iterable[_T],
48
90
  func: Callable[[_T], THashable],
49
91
  /,
50
92
  *,
93
+ transform: Callable[[_T], _U] | None = None,
51
94
  list: bool = False, # noqa: A002
52
- ) -> Mapping[THashable, Iterator[_T]] | Mapping[THashable, Sequence[_T]]:
95
+ ) -> (
96
+ Mapping[THashable, Iterator[_T]]
97
+ | Mapping[THashable, Iterator[_U]]
98
+ | Mapping[THashable, Sequence[_T]]
99
+ | Mapping[THashable, Sequence[_U]]
100
+ ):
53
101
  """Bucket the values of iterable into a mapping."""
54
102
  b = bucket(iterable, func)
55
103
  mapping = {key: b[key] for key in b}
56
- if list:
57
- return {key: builtins.list(value) for key, value in mapping.items()}
58
- return mapping
104
+ match transform, list:
105
+ case None, False:
106
+ return mapping
107
+ case None, True:
108
+ return {k: builtins.list(v) for k, v in mapping.items()}
109
+ case _, False:
110
+ return {k: map(transform, v) for k, v in mapping.items()}
111
+ case _, True:
112
+ return {k: builtins.list(map(transform, v)) for k, v in mapping.items()}
113
+ case _ as never:
114
+ assert_never(never)
59
115
 
60
116
 
61
117
  ##
utilities/astor.py DELETED
@@ -1,28 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from contextlib import suppress
4
- from subprocess import CalledProcessError, check_call
5
- from typing import TYPE_CHECKING
6
-
7
- from astor import to_source
8
-
9
- from utilities.tempfile import TemporaryDirectory
10
-
11
- if TYPE_CHECKING:
12
- from ast import Module
13
-
14
-
15
- def module_to_source(module: Module, /) -> str:
16
- """Write a module as a `ruff`-formatted string."""
17
- src = to_source(module)
18
- with TemporaryDirectory() as temp:
19
- path = temp.joinpath("temp.py")
20
- with path.open(mode="w") as fh:
21
- _ = fh.write(src)
22
- with suppress(CalledProcessError, FileNotFoundError):
23
- _ = check_call(["ruff", "format", str(path)])
24
- with path.open() as fh:
25
- return fh.read()
26
-
27
-
28
- __all__ = ["module_to_source"]