dycw-utilities 0.151.10__py3-none-any.whl → 0.151.11__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.
- {dycw_utilities-0.151.10.dist-info → dycw_utilities-0.151.11.dist-info}/METADATA +1 -1
- {dycw_utilities-0.151.10.dist-info → dycw_utilities-0.151.11.dist-info}/RECORD +7 -7
- utilities/__init__.py +1 -1
- utilities/period.py +33 -12
- {dycw_utilities-0.151.10.dist-info → dycw_utilities-0.151.11.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.151.10.dist-info → dycw_utilities-0.151.11.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.151.10.dist-info → dycw_utilities-0.151.11.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=QFtmxXQUOY461TnnnmD5VQHWJT3vLCqDXSEDvXwfrUM,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
|
@@ -44,7 +44,7 @@ utilities/orjson.py,sha256=Gzxn-s55pGFKV8DdsYXpp-Gr3r-5KdacYUd_GHMBogM,40088
|
|
44
44
|
utilities/os.py,sha256=mFvjydySvjtSXpk7tLStUJcndauAoujxUUmj_CO7LWY,3778
|
45
45
|
utilities/parse.py,sha256=JcJn5yXKhIWXBCwgBdPsyu7Hvcuw6kyEdqvaebCaI9k,17951
|
46
46
|
utilities/pathlib.py,sha256=77wT9naY2Nnrbar8nJiIYd2r3MfabMQM9VguuuivrdQ,8481
|
47
|
-
utilities/period.py,sha256=
|
47
|
+
utilities/period.py,sha256=c4-N8N1GIUyomoHmSO7yPfYgK8tc__dxNSB79knlx2w,12471
|
48
48
|
utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
|
49
49
|
utilities/platform.py,sha256=pTn7gw6N4T6LdKrf0virwarof_mze9WtoQlrGMzhGVI,2798
|
50
50
|
utilities/polars.py,sha256=x4x3i08ldcDyKVEa8rcyAyacHKjok30K2v79yhoIn2Y,73243
|
@@ -89,8 +89,8 @@ utilities/zoneinfo.py,sha256=FBMcUQ4662Aq8SsuCL1OAhDQiyANmVjtb-C30DRrWoE,1966
|
|
89
89
|
utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
90
90
|
utilities/pytest_plugins/pytest_randomly.py,sha256=NXzCcGKbpgYouz5yehKb4jmxmi2SexKKpgF4M65bi10,414
|
91
91
|
utilities/pytest_plugins/pytest_regressions.py,sha256=Iwhfv_OJH7UCPZCfoh7ugZ2Xjqjil-BBBsOb8sDwiGI,1471
|
92
|
-
dycw_utilities-0.151.
|
93
|
-
dycw_utilities-0.151.
|
94
|
-
dycw_utilities-0.151.
|
95
|
-
dycw_utilities-0.151.
|
96
|
-
dycw_utilities-0.151.
|
92
|
+
dycw_utilities-0.151.11.dist-info/METADATA,sha256=_R0ltbaJCdA-g4I1cTYINPyOhEa1S6ImCwHMAXdG0HI,1697
|
93
|
+
dycw_utilities-0.151.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
94
|
+
dycw_utilities-0.151.11.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
|
95
|
+
dycw_utilities-0.151.11.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
96
|
+
dycw_utilities-0.151.11.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
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
|
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
|
-
|
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:
|
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) ->
|
127
|
+
def to_dict(self) -> PeriodDict[Date]:
|
113
128
|
"""Convert the period to a dictionary."""
|
114
|
-
return
|
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:
|
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) ->
|
182
|
+
def to_dict(self) -> PeriodDict[Time]:
|
168
183
|
"""Convert the period to a dictionary."""
|
169
|
-
return
|
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:
|
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) ->
|
321
|
+
def to_dict(self) -> PeriodDict[ZonedDateTime]:
|
307
322
|
"""Convert the period to a dictionary."""
|
308
|
-
return
|
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__ = [
|
364
|
+
__all__ = [
|
365
|
+
"DatePeriod",
|
366
|
+
"PeriodDict",
|
367
|
+
"PeriodError",
|
368
|
+
"TimePeriod",
|
369
|
+
"ZonedDateTimePeriod",
|
370
|
+
]
|
File without changes
|
File without changes
|
File without changes
|