dycw-utilities 0.151.10__py3-none-any.whl → 0.151.12__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.151.10
3
+ Version: 0.151.12
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=ohf_5FPJbFDOjflrHr5JwHamf7937DDMR15Y5Jsb2-U,61
1
+ utilities/__init__.py,sha256=CToBsJ7ahHohUxklvuPmWZ4QaYXiq2IS6xmnb7POeZo,61
2
2
  utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
3
3
  utilities/asyncio.py,sha256=r75HVwm6QoCOz7bEe3_KO47G4_IIhNCYcPDrJTi4i_4,16777
4
4
  utilities/atomicwrites.py,sha256=tPo6r-Rypd9u99u66B9z86YBPpnLrlHtwox_8Z7T34Y,5790
@@ -11,7 +11,6 @@ utilities/contextvars.py,sha256=J8OhC7jqozAGYOCe2KUWysbPXNGe5JYz3HfaY_mIs08,883
11
11
  utilities/cryptography.py,sha256=_CiK_K6c_-uQuUhsUNjNjTL-nqxAh4_1zTfS11Xe120,972
12
12
  utilities/cvxpy.py,sha256=Rv1-fD-XYerosCavRF8Pohop2DBkU3AlFaGTfD8AEAA,13776
13
13
  utilities/dataclasses.py,sha256=G05UH-fqUbcRPjQ8arK6K0Ap2fRbzEm0SZahJKCqYfY,32643
14
- utilities/dnspython.py,sha256=HfFaxjA_25XhjsTM5Bg03GCFatKzL8dOV4E0c9oMsho,384
15
14
  utilities/enum.py,sha256=5l6pwZD1cjSlVW4ss-zBPspWvrbrYrdtJWcg6f5_J5w,5781
16
15
  utilities/errors.py,sha256=mFlDGSM0LI1jZ1pbqwLAH3ttLZ2JVIxyZLojw8tGVZU,1479
17
16
  utilities/eventkit.py,sha256=FRCZisJfY9hAS9GHV4ZO3ZHDs89XZod7Xf99WzBt7jQ,12636
@@ -44,10 +43,10 @@ utilities/orjson.py,sha256=Gzxn-s55pGFKV8DdsYXpp-Gr3r-5KdacYUd_GHMBogM,40088
44
43
  utilities/os.py,sha256=mFvjydySvjtSXpk7tLStUJcndauAoujxUUmj_CO7LWY,3778
45
44
  utilities/parse.py,sha256=JcJn5yXKhIWXBCwgBdPsyu7Hvcuw6kyEdqvaebCaI9k,17951
46
45
  utilities/pathlib.py,sha256=77wT9naY2Nnrbar8nJiIYd2r3MfabMQM9VguuuivrdQ,8481
47
- utilities/period.py,sha256=SpgccCm1vsM5ESHj26upVHRERxELzri8No9XU60H_H8,12201
46
+ utilities/period.py,sha256=c4-N8N1GIUyomoHmSO7yPfYgK8tc__dxNSB79knlx2w,12471
48
47
  utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
49
48
  utilities/platform.py,sha256=pTn7gw6N4T6LdKrf0virwarof_mze9WtoQlrGMzhGVI,2798
50
- utilities/polars.py,sha256=x4x3i08ldcDyKVEa8rcyAyacHKjok30K2v79yhoIn2Y,73243
49
+ utilities/polars.py,sha256=uxV4liIQoCO92aERDO-AMfa8Es_-xCKgwZoyTO3PazQ,74410
51
50
  utilities/polars_ols.py,sha256=Uc9V5kvlWZ5cU93lKZ-cfAKdVFFw81tqwLW9PxtUvMs,5618
52
51
  utilities/postgres.py,sha256=juXaOguCCX4oAw4y2JajRVIhhKKZarCyapNyyr4Tn4Q,12538
53
52
  utilities/pottery.py,sha256=u0uvyGgYyujxftEMlsv6ppYTKQoVVjHt5jnVxxYz9s4,6596
@@ -89,8 +88,8 @@ utilities/zoneinfo.py,sha256=FBMcUQ4662Aq8SsuCL1OAhDQiyANmVjtb-C30DRrWoE,1966
89
88
  utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
90
89
  utilities/pytest_plugins/pytest_randomly.py,sha256=NXzCcGKbpgYouz5yehKb4jmxmi2SexKKpgF4M65bi10,414
91
90
  utilities/pytest_plugins/pytest_regressions.py,sha256=Iwhfv_OJH7UCPZCfoh7ugZ2Xjqjil-BBBsOb8sDwiGI,1471
92
- dycw_utilities-0.151.10.dist-info/METADATA,sha256=67Rkmup754-j6tJJPOspiNytoZEOdhzhva8-hnef3Mc,1697
93
- dycw_utilities-0.151.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
- dycw_utilities-0.151.10.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
95
- dycw_utilities-0.151.10.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
96
- dycw_utilities-0.151.10.dist-info/RECORD,,
91
+ dycw_utilities-0.151.12.dist-info/METADATA,sha256=NGGUpkviTSqFVd23pWs_5MGWRsb6OLal8p1dbJWqMIc,1697
92
+ dycw_utilities-0.151.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
+ dycw_utilities-0.151.12.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
94
+ dycw_utilities-0.151.12.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
+ dycw_utilities-0.151.12.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.151.10"
3
+ __version__ = "0.151.12"
utilities/period.py CHANGED
@@ -2,7 +2,16 @@ from __future__ import annotations
2
2
 
3
3
  import datetime as dt
4
4
  from dataclasses import dataclass
5
- from typing import TYPE_CHECKING, Any, Self, TypedDict, assert_never, overload, override
5
+ from typing import (
6
+ TYPE_CHECKING,
7
+ Any,
8
+ Self,
9
+ TypedDict,
10
+ TypeVar,
11
+ assert_never,
12
+ overload,
13
+ override,
14
+ )
6
15
  from zoneinfo import ZoneInfo
7
16
 
8
17
  from whenever import Date, DateDelta, PlainDateTime, Time, TimeDelta, ZonedDateTime
@@ -16,8 +25,14 @@ from utilities.zoneinfo import UTC, ensure_time_zone, get_time_zone_name
16
25
  if TYPE_CHECKING:
17
26
  from utilities.types import TimeZoneLike
18
27
 
28
+ _TDate_co = TypeVar("_TDate_co", bound=Date | dt.date, covariant=True)
29
+ _TTime_co = TypeVar("_TTime_co", bound=Time | dt.time, covariant=True)
30
+ _TDateTime_co = TypeVar(
31
+ "_TDateTime_co", bound=ZonedDateTime | dt.datetime, covariant=True
32
+ )
19
33
 
20
- class _PeriodAsDict[T: Date | Time | ZonedDateTime | dt.date | dt.time | dt.datetime](
34
+
35
+ class PeriodDict[T: Date | Time | ZonedDateTime | dt.date | dt.time | dt.datetime](
21
36
  TypedDict
22
37
  ):
23
38
  start: T
@@ -85,7 +100,7 @@ class DatePeriod:
85
100
  return f"{fc(start)}-{fc(end)}"
86
101
 
87
102
  @classmethod
88
- def from_dict(cls, mapping: _PeriodAsDict[Date | dt.date], /) -> Self:
103
+ def from_dict(cls, mapping: PeriodDict[_TDate_co], /) -> Self:
89
104
  """Convert the dictionary to a period."""
90
105
  match mapping["start"]:
91
106
  case Date() as start:
@@ -109,9 +124,9 @@ class DatePeriod:
109
124
  """Replace elements of the period."""
110
125
  return replace_non_sentinel(self, start=start, end=end)
111
126
 
112
- def to_dict(self) -> _PeriodAsDict[Date]:
127
+ def to_dict(self) -> PeriodDict[Date]:
113
128
  """Convert the period to a dictionary."""
114
- return _PeriodAsDict(start=self.start, end=self.end)
129
+ return PeriodDict(start=self.start, end=self.end)
115
130
 
116
131
 
117
132
  @dataclass(repr=False, order=True, unsafe_hash=True, kw_only=False)
@@ -140,7 +155,7 @@ class TimePeriod:
140
155
  return DatePeriod(start, end).at((self.start, self.end), time_zone=time_zone)
141
156
 
142
157
  @classmethod
143
- def from_dict(cls, mapping: _PeriodAsDict[Time | dt.time], /) -> Self:
158
+ def from_dict(cls, mapping: PeriodDict[_TTime_co], /) -> Self:
144
159
  """Convert the dictionary to a period."""
145
160
  match mapping["start"]:
146
161
  case Time() as start:
@@ -164,9 +179,9 @@ class TimePeriod:
164
179
  """Replace elements of the period."""
165
180
  return replace_non_sentinel(self, start=start, end=end)
166
181
 
167
- def to_dict(self) -> _PeriodAsDict[Time]:
182
+ def to_dict(self) -> PeriodDict[Time]:
168
183
  """Convert the period to a dictionary."""
169
- return _PeriodAsDict(start=self.start, end=self.end)
184
+ return PeriodDict(start=self.start, end=self.end)
170
185
 
171
186
 
172
187
  @dataclass(repr=False, order=True, unsafe_hash=True, kw_only=False)
@@ -271,7 +286,7 @@ class ZonedDateTimePeriod:
271
286
  return f"{fc(start.to_plain())}-{fc(end, fmt='%Y%m%dT%H')}"
272
287
 
273
288
  @classmethod
274
- def from_dict(cls, mapping: _PeriodAsDict[ZonedDateTime | dt.datetime], /) -> Self:
289
+ def from_dict(cls, mapping: PeriodDict[_TDateTime_co], /) -> Self:
275
290
  """Convert the dictionary to a period."""
276
291
  match mapping["start"]:
277
292
  case ZonedDateTime() as start:
@@ -303,9 +318,9 @@ class ZonedDateTimePeriod:
303
318
  """The time zone of the period."""
304
319
  return ZoneInfo(self.start.tz)
305
320
 
306
- def to_dict(self) -> _PeriodAsDict[ZonedDateTime]:
321
+ def to_dict(self) -> PeriodDict[ZonedDateTime]:
307
322
  """Convert the period to a dictionary."""
308
- return _PeriodAsDict(start=self.start, end=self.end)
323
+ return PeriodDict(start=self.start, end=self.end)
309
324
 
310
325
  def to_tz(self, time_zone: TimeZoneLike, /) -> Self:
311
326
  """Convert the time zone."""
@@ -346,4 +361,10 @@ class _PeriodExactEqArgumentsError(PeriodError):
346
361
  return f"Invalid arguments; got {self.args}"
347
362
 
348
363
 
349
- __all__ = ["DatePeriod", "PeriodError", "TimePeriod", "ZonedDateTimePeriod"]
364
+ __all__ = [
365
+ "DatePeriod",
366
+ "PeriodDict",
367
+ "PeriodError",
368
+ "TimePeriod",
369
+ "ZonedDateTimePeriod",
370
+ ]
utilities/polars.py CHANGED
@@ -7,7 +7,7 @@ from collections.abc import Set as AbstractSet
7
7
  from contextlib import suppress
8
8
  from dataclasses import asdict, dataclass
9
9
  from functools import partial, reduce
10
- from itertools import chain, product
10
+ from itertools import chain, pairwise, product
11
11
  from math import ceil, log
12
12
  from pathlib import Path
13
13
  from typing import TYPE_CHECKING, Any, Literal, assert_never, cast, overload, override
@@ -1471,6 +1471,37 @@ class _GetSeriesNumberOfDecimalsAllNullError(GetSeriesNumberOfDecimalsError):
1471
1471
  ##
1472
1472
 
1473
1473
 
1474
+ @overload
1475
+ def increasing_horizontal(*columns: ExprLike) -> Expr: ...
1476
+ @overload
1477
+ def increasing_horizontal(*columns: Series) -> Series: ...
1478
+ @overload
1479
+ def increasing_horizontal(*columns: IntoExprColumn) -> Expr | Series: ...
1480
+ def increasing_horizontal(*columns: IntoExprColumn) -> Expr | Series:
1481
+ """Check if a set of columns are increasing."""
1482
+ columns2 = ensure_expr_or_series_many(*columns)
1483
+ if len(columns2) == 0:
1484
+ return lit(value=True, dtype=Boolean)
1485
+ return all_horizontal(prev < curr for prev, curr in pairwise(columns2))
1486
+
1487
+
1488
+ @overload
1489
+ def decreasing_horizontal(*columns: ExprLike) -> Expr: ...
1490
+ @overload
1491
+ def decreasing_horizontal(*columns: Series) -> Series: ...
1492
+ @overload
1493
+ def decreasing_horizontal(*columns: IntoExprColumn) -> Expr | Series: ...
1494
+ def decreasing_horizontal(*columns: IntoExprColumn) -> Expr | Series:
1495
+ """Check if a set of columns are decreasing."""
1496
+ columns2 = ensure_expr_or_series_many(*columns)
1497
+ if len(columns2) == 0:
1498
+ return lit(value=True, dtype=Boolean)
1499
+ return all_horizontal(prev > curr for prev, curr in pairwise(columns2))
1500
+
1501
+
1502
+ ##
1503
+
1504
+
1474
1505
  def insert_after(df: DataFrame, column: str, value: IntoExprColumn, /) -> DataFrame:
1475
1506
  """Insert a series after an existing column; not in-place."""
1476
1507
  columns = df.columns
@@ -2472,6 +2503,7 @@ __all__ = [
2472
2503
  "cross",
2473
2504
  "dataclass_to_dataframe",
2474
2505
  "dataclass_to_schema",
2506
+ "decreasing_horizontal",
2475
2507
  "deserialize_dataframe",
2476
2508
  "drop_null_struct_series",
2477
2509
  "ensure_data_type",
@@ -2483,6 +2515,7 @@ __all__ = [
2483
2515
  "get_expr_name",
2484
2516
  "get_frequency_spectrum",
2485
2517
  "get_series_number_of_decimals",
2518
+ "increasing_horizontal",
2486
2519
  "insert_after",
2487
2520
  "insert_before",
2488
2521
  "insert_between",
utilities/dnspython.py DELETED
@@ -1,17 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from ipaddress import IPv4Address
4
-
5
- from dns.resolver import resolve
6
-
7
- from utilities.functools import cache
8
-
9
-
10
- @cache
11
- def nslookup(address: str, /) -> list[IPv4Address]:
12
- """Look up a set of addresses."""
13
- ans = resolve(address) # skipif-ci-and-mac
14
- return [IPv4Address(str(rd)) for rd in ans] # skipif-ci-and-mac
15
-
16
-
17
- __all__ = ["nslookup"]