dycw-utilities 0.112.13__py3-none-any.whl → 0.113.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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.112.13
3
+ Version: 0.113.0
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -137,7 +137,6 @@ Provides-Extra: zzz-test-pickle
137
137
  Requires-Dist: atomicwrites<1.5,>=1.4.1; extra == 'zzz-test-pickle'
138
138
  Provides-Extra: zzz-test-platform
139
139
  Provides-Extra: zzz-test-polars
140
- Requires-Dist: dacite<1.10,>=1.9.2; extra == 'zzz-test-polars'
141
140
  Requires-Dist: polars-lts-cpu<1.30,>=1.29.0; extra == 'zzz-test-polars'
142
141
  Requires-Dist: whenever<0.8,>=0.7.3; extra == 'zzz-test-polars'
143
142
  Provides-Extra: zzz-test-pqdm
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=BNmG5-3ficTmieJpU_Y3lnG8RPyYTmqf6b0EGn9rM5I,61
1
+ utilities/__init__.py,sha256=TPZxfh1oiJcBvVAm3h0rBfeG5K-2E_CPiVywRrSQUJw,60
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
3
  utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
4
4
  utilities/asyncio.py,sha256=41oQUurWMvadFK5gFnaG21hMM0Vmfn2WS6OpC0R9mas,14757
@@ -35,7 +35,7 @@ utilities/luigi.py,sha256=fpH9MbxJDuo6-k9iCXRayFRtiVbUtibCJKugf7ygpv0,5988
35
35
  utilities/math.py,sha256=TexfvLCI12d9Sw5_W4pKVBZ3nRr3zk2iPkcEU7xdEWU,26771
36
36
  utilities/memory_profiler.py,sha256=tf2C51P2lCujPGvRt2Rfc7VEw5LDXmVPCG3z_AvBmbU,962
37
37
  utilities/modules.py,sha256=iuvLluJya-hvl1Q25-Jk3dLgx2Es3ck4SjJiEkAlVTs,3195
38
- utilities/more_itertools.py,sha256=CPUxrMAcTwRxbzbhiqPKi3Xx9hxqI0t6gkWjutaibGk,5534
38
+ utilities/more_itertools.py,sha256=6T0225gBFZtv47-B0JRFOKMz836Wg3Hct79ePPLGpuo,5827
39
39
  utilities/numpy.py,sha256=Xn23sA2ZbVNqwUYEgNJD3XBYH6IbCri_WkHSNhg3NkY,26122
40
40
  utilities/operator.py,sha256=0M2yZJ0PODH47ogFEnkGMBe_cfxwZR02T_92LZVZvHo,3715
41
41
  utilities/optuna.py,sha256=loyJGWTzljgdJaoLhP09PT8Jz6o_pwBOwehY33lHkhw,1923
@@ -46,7 +46,7 @@ utilities/pathlib.py,sha256=31WPMXdLIyXgYOMMl_HOI2wlo66MGSE-cgeelk-Lias,1410
46
46
  utilities/period.py,sha256=RWfcNVoNlW07RNdU47g_zuLZMKbtgfK4bE6G-9tVjY8,11024
47
47
  utilities/pickle.py,sha256=Bhvd7cZl-zQKQDFjUerqGuSKlHvnW1K2QXeU5UZibtg,657
48
48
  utilities/platform.py,sha256=NU7ycTvAXAG-fdYmDXaM1m4EOml2cGiaYwaUzfzSqyU,1767
49
- utilities/polars.py,sha256=bo2Rhukk2eXxe1RMfu2uvEjTQTd9SmOi8mGW4BRG82c,67288
49
+ utilities/polars.py,sha256=fxfSm4xVHwKvRxu50IhYNKCKOagp12FdwsVf04ARKpk,63692
50
50
  utilities/polars_ols.py,sha256=efhXf0gjrHUpQrvS6a7g8yJQJWf_ATKtJnqqF2inCOU,5680
51
51
  utilities/pqdm.py,sha256=foRytQybmOQ05pjt5LF7ANyzrIa--4ScDE3T2wd31a4,3118
52
52
  utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -87,7 +87,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
87
87
  utilities/whenever.py,sha256=iLRP_-8CZtBpHKbGZGu-kjSMg1ZubJ-VSmgSy7Eudxw,17787
88
88
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
89
89
  utilities/zoneinfo.py,sha256=-Xm57PMMwDTYpxJdkiJG13wnbwK--I7XItBh5WVhD-o,1874
90
- dycw_utilities-0.112.13.dist-info/METADATA,sha256=ry5WZn_RrS8mPfvF1X5nC6BG2rghvsLdY105g8M70kQ,13005
91
- dycw_utilities-0.112.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
- dycw_utilities-0.112.13.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
93
- dycw_utilities-0.112.13.dist-info/RECORD,,
90
+ dycw_utilities-0.113.0.dist-info/METADATA,sha256=u1S471FuT-D9JfhjdhHpcj1kxCiaLrpFeoI2eNz7vdY,12941
91
+ dycw_utilities-0.113.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
+ dycw_utilities-0.113.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
93
+ dycw_utilities-0.113.0.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.112.13"
3
+ __version__ = "0.113.0"
@@ -32,6 +32,9 @@ _T = TypeVar("_T")
32
32
  _U = TypeVar("_U")
33
33
 
34
34
 
35
+ ##
36
+
37
+
35
38
  @overload
36
39
  def bucket_mapping(
37
40
  iterable: Iterable[_T], func: Callable[[_T], THashable], /, *, list: Literal[True]
@@ -55,6 +58,20 @@ def bucket_mapping(
55
58
  return mapping
56
59
 
57
60
 
61
+ ##
62
+
63
+
64
+ def partition_list(
65
+ pred: Callable[[_T], bool], iterable: Iterable[_T], /
66
+ ) -> tuple[list[_T], list[_T]]:
67
+ """Partition with lists."""
68
+ false, true = partition(pred, iterable)
69
+ return list(false), list(true)
70
+
71
+
72
+ ##
73
+
74
+
58
75
  def partition_typeguard(
59
76
  pred: Callable[[_T], TypeGuard[_U]], iterable: Iterable[_T], /
60
77
  ) -> tuple[Iterator[_T], Iterator[_U]]:
@@ -64,6 +81,9 @@ def partition_typeguard(
64
81
  return false, true
65
82
 
66
83
 
84
+ ##
85
+
86
+
67
87
  class peekable(_peekable, Generic[_T]): # noqa: N801
68
88
  """Peekable which supports dropwhile/takewhile methods."""
69
89
 
@@ -98,6 +118,9 @@ class peekable(_peekable, Generic[_T]): # noqa: N801
98
118
  yield next(self)
99
119
 
100
120
 
121
+ ##
122
+
123
+
101
124
  @dataclass(kw_only=True, slots=True)
102
125
  class Split(Generic[_T]):
103
126
  """An iterable split into head/tail."""
@@ -184,4 +207,11 @@ def _yield_splits3(
184
207
  )
185
208
 
186
209
 
187
- __all__ = ["Split", "bucket_mapping", "partition_typeguard", "peekable", "yield_splits"]
210
+ __all__ = [
211
+ "Split",
212
+ "bucket_mapping",
213
+ "partition_list",
214
+ "partition_typeguard",
215
+ "peekable",
216
+ "yield_splits",
217
+ ]
utilities/polars.py CHANGED
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import datetime as dt
4
4
  import enum
5
- from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
5
+ from collections.abc import Callable, Iterator, Sequence
6
6
  from collections.abc import Set as AbstractSet
7
7
  from contextlib import suppress
8
8
  from dataclasses import asdict, dataclass
@@ -15,7 +15,6 @@ from typing import (
15
15
  Any,
16
16
  Generic,
17
17
  Literal,
18
- TypeGuard,
19
18
  TypeVar,
20
19
  assert_never,
21
20
  cast,
@@ -109,10 +108,9 @@ from utilities.warnings import suppress_warnings
109
108
  from utilities.zoneinfo import UTC, ensure_time_zone, get_time_zone_name
110
109
 
111
110
  if TYPE_CHECKING:
112
- from collections.abc import Callable, Iterator, Sequence
111
+ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
113
112
  from collections.abc import Set as AbstractSet
114
113
 
115
- from dacite.data import Data
116
114
  from polars._typing import (
117
115
  IntoExpr, # pyright: ignore[reportPrivateImportUsage]
118
116
  IntoExprColumn, # pyright: ignore[reportPrivateImportUsage]
@@ -126,13 +124,7 @@ if TYPE_CHECKING:
126
124
 
127
125
  from utilities.numpy import NDArrayB, NDArrayF
128
126
  from utilities.statsmodels import ACFMissing
129
- from utilities.types import (
130
- Dataclass,
131
- MaybeIterable,
132
- StrMapping,
133
- TDataclass,
134
- TimeZoneLike,
135
- )
127
+ from utilities.types import Dataclass, MaybeIterable, StrMapping, TimeZoneLike
136
128
 
137
129
 
138
130
  _T = TypeVar("_T")
@@ -2134,116 +2126,6 @@ def week_num(column: IntoExprColumn, /, *, start: WeekDay = "mon") -> Expr | Ser
2134
2126
  ##
2135
2127
 
2136
2128
 
2137
- @overload
2138
- def yield_struct_series_elements(
2139
- series: Series, /, *, strict: Literal[True]
2140
- ) -> Iterator[Mapping[str, Any]]: ...
2141
- @overload
2142
- def yield_struct_series_elements(
2143
- series: Series, /, *, strict: Literal[False]
2144
- ) -> Iterator[Mapping[str, Any] | None]: ...
2145
- @overload
2146
- def yield_struct_series_elements(
2147
- series: Series, /, *, strict: bool = False
2148
- ) -> Iterator[Mapping[str, Any] | None]: ...
2149
- def yield_struct_series_elements(
2150
- series: Series, /, *, strict: bool = False
2151
- ) -> Iterator[Mapping[str, Any] | None]:
2152
- """Yield the elements of a struct-dtype Series as optional mappings."""
2153
- if not isinstance(series.dtype, Struct):
2154
- raise _YieldStructSeriesElementsDTypeError(series=series)
2155
- if strict and series.is_null().any():
2156
- raise _YieldStructSeriesElementsNullElementsError(series=series)
2157
- for value in series:
2158
- yield _yield_struct_series_element_remove_nulls(value)
2159
-
2160
-
2161
- def _yield_struct_series_element_remove_nulls(obj: Any, /) -> Any:
2162
- if not _yield_struct_series_element_is_mapping_of_str(obj):
2163
- return obj
2164
- if any(_yield_struct_series_element_is_mapping_of_str(v) for v in obj.values()):
2165
- result = {
2166
- k: _yield_struct_series_element_remove_nulls(v) for k, v in obj.items()
2167
- }
2168
- if result == obj:
2169
- return result
2170
- return _yield_struct_series_element_remove_nulls(result)
2171
- return None if all(v is None for v in obj.values()) else obj
2172
-
2173
-
2174
- def _yield_struct_series_element_is_mapping_of_str(
2175
- obj: Any, /
2176
- ) -> TypeGuard[Mapping[str, Any]]:
2177
- return isinstance(obj, Mapping) and is_iterable_of(obj, str)
2178
-
2179
-
2180
- @dataclass(kw_only=True, slots=True)
2181
- class YieldStructSeriesElementsError(Exception):
2182
- series: Series
2183
-
2184
-
2185
- @dataclass(kw_only=True, slots=True)
2186
- class _YieldStructSeriesElementsDTypeError(YieldStructSeriesElementsError):
2187
- @override
2188
- def __str__(self) -> str:
2189
- return f"Series must have Struct-dtype; got {self.series.dtype}"
2190
-
2191
-
2192
- @dataclass(kw_only=True, slots=True)
2193
- class _YieldStructSeriesElementsNullElementsError(YieldStructSeriesElementsError):
2194
- @override
2195
- def __str__(self) -> str:
2196
- return f"Series must not have nulls; got {self.series}"
2197
-
2198
-
2199
- ##
2200
-
2201
-
2202
- @overload
2203
- def yield_struct_series_dataclasses(
2204
- series: Series,
2205
- cls: type[TDataclass],
2206
- /,
2207
- *,
2208
- forward_references: dict[str, Any] | None = None,
2209
- check_types: bool = True,
2210
- strict: Literal[True],
2211
- ) -> Iterator[TDataclass]: ...
2212
- @overload
2213
- def yield_struct_series_dataclasses(
2214
- series: Series,
2215
- cls: type[TDataclass],
2216
- /,
2217
- *,
2218
- forward_references: dict[str, Any] | None = None,
2219
- check_types: bool = True,
2220
- strict: bool = False,
2221
- ) -> Iterator[TDataclass | None]: ...
2222
- def yield_struct_series_dataclasses(
2223
- series: Series,
2224
- cls: type[TDataclass],
2225
- /,
2226
- *,
2227
- forward_references: dict[str, Any] | None = None,
2228
- check_types: bool = True,
2229
- strict: bool = False,
2230
- ) -> Iterator[TDataclass | None]:
2231
- """Yield the elements of a struct-dtype Series as dataclasses."""
2232
- from dacite import Config, from_dict
2233
-
2234
- config = Config(
2235
- forward_references=forward_references, check_types=check_types, strict=True
2236
- )
2237
- for value in yield_struct_series_elements(series, strict=strict):
2238
- if value is None:
2239
- yield None
2240
- else:
2241
- yield from_dict(cls, cast("Data", value), config=config)
2242
-
2243
-
2244
- ##
2245
-
2246
-
2247
2129
  def zoned_datetime(
2248
2130
  *, time_unit: TimeUnit = "us", time_zone: TimeZoneLike = UTC
2249
2131
  ) -> Datetime:
@@ -2272,7 +2154,6 @@ __all__ = [
2272
2154
  "IsNullStructSeriesError",
2273
2155
  "SetFirstRowAsColumnsError",
2274
2156
  "StructFromDataClassError",
2275
- "YieldStructSeriesElementsError",
2276
2157
  "acf",
2277
2158
  "adjust_frequencies",
2278
2159
  "append_dataclass",
@@ -2319,7 +2200,5 @@ __all__ = [
2319
2200
  "try_reify_expr",
2320
2201
  "uniform",
2321
2202
  "unique_element",
2322
- "yield_struct_series_dataclasses",
2323
- "yield_struct_series_elements",
2324
2203
  "zoned_datetime",
2325
2204
  ]