dycw-utilities 0.108.4__py3-none-any.whl → 0.109.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.
- {dycw_utilities-0.108.4.dist-info → dycw_utilities-0.109.0.dist-info}/METADATA +1 -1
- {dycw_utilities-0.108.4.dist-info → dycw_utilities-0.109.0.dist-info}/RECORD +7 -7
- utilities/__init__.py +1 -1
- utilities/parse.py +2 -2
- utilities/polars.py +0 -99
- {dycw_utilities-0.108.4.dist-info → dycw_utilities-0.109.0.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.108.4.dist-info → dycw_utilities-0.109.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256
|
1
|
+
utilities/__init__.py,sha256=us3aLi645m07ZoZciss9gQZW8TJND1cejqEh_im4aL8,60
|
2
2
|
utilities/altair.py,sha256=NSyDsm8QlkAGmsGdxVwCkHnPxt_35yJBa9Lg7bz9Ays,9054
|
3
3
|
utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
|
4
4
|
utilities/asyncio.py,sha256=41oQUurWMvadFK5gFnaG21hMM0Vmfn2WS6OpC0R9mas,14757
|
@@ -40,12 +40,12 @@ utilities/operator.py,sha256=0M2yZJ0PODH47ogFEnkGMBe_cfxwZR02T_92LZVZvHo,3715
|
|
40
40
|
utilities/optuna.py,sha256=loyJGWTzljgdJaoLhP09PT8Jz6o_pwBOwehY33lHkhw,1923
|
41
41
|
utilities/orjson.py,sha256=DW5pOpMyrR5Q8caQYly9AqRPazDBqrWv5GRWfULqka4,36291
|
42
42
|
utilities/os.py,sha256=D_FyyT-6TtqiN9KSS7c9g1fnUtgxmyMtzAjmYLkk46A,3587
|
43
|
-
utilities/parse.py,sha256=
|
43
|
+
utilities/parse.py,sha256=yLLH51VNwmcWbEvwqh6M-weWt7NIayd7No67Oe80S3k,4585
|
44
44
|
utilities/pathlib.py,sha256=31WPMXdLIyXgYOMMl_HOI2wlo66MGSE-cgeelk-Lias,1410
|
45
45
|
utilities/period.py,sha256=ikHXsWtDLr553cfH6p9mMaiCnIAP69B7q84ckWV3HaA,10884
|
46
46
|
utilities/pickle.py,sha256=Bhvd7cZl-zQKQDFjUerqGuSKlHvnW1K2QXeU5UZibtg,657
|
47
47
|
utilities/platform.py,sha256=NU7ycTvAXAG-fdYmDXaM1m4EOml2cGiaYwaUzfzSqyU,1767
|
48
|
-
utilities/polars.py,sha256=
|
48
|
+
utilities/polars.py,sha256=ZXiHLkn6CbRh0_e0db5KRjHPU0LAedwzGno7k9fsiIo,48917
|
49
49
|
utilities/pqdm.py,sha256=foRytQybmOQ05pjt5LF7ANyzrIa--4ScDE3T2wd31a4,3118
|
50
50
|
utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
51
51
|
utilities/pydantic.py,sha256=f6qtR5mO2YMuyvNmbaEj5YeD9eGA4YYfb7Bjzh9jUs0,1845
|
@@ -84,7 +84,7 @@ utilities/warnings.py,sha256=yUgjnmkCRf6QhdyAXzl7u0qQFejhQG3PrjoSwxpbHrs,1819
|
|
84
84
|
utilities/whenever.py,sha256=5x2t47VJmJRWcd_NLFy54NkB3uom-XQYxEbLtEfL1bs,17775
|
85
85
|
utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
|
86
86
|
utilities/zoneinfo.py,sha256=-DQz5a0Ikw9jfSZtL0BEQkXOMC9yGn_xiJYNCLMiqEc,1989
|
87
|
-
dycw_utilities-0.
|
88
|
-
dycw_utilities-0.
|
89
|
-
dycw_utilities-0.
|
90
|
-
dycw_utilities-0.
|
87
|
+
dycw_utilities-0.109.0.dist-info/METADATA,sha256=7Urd3hro439NaLJ2Kkzu7mJNlYt5qxb3HmbzrcZwbkQ,13004
|
88
|
+
dycw_utilities-0.109.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
89
|
+
dycw_utilities-0.109.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
90
|
+
dycw_utilities-0.109.0.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/parse.py
CHANGED
@@ -6,7 +6,7 @@ from dataclasses import dataclass
|
|
6
6
|
from enum import Enum
|
7
7
|
from pathlib import Path
|
8
8
|
from types import NoneType
|
9
|
-
from typing import Any,
|
9
|
+
from typing import Any, override
|
10
10
|
|
11
11
|
from utilities.datetime import is_subclass_date_not_datetime
|
12
12
|
from utilities.enum import ParseEnumError, parse_enum
|
@@ -14,7 +14,7 @@ from utilities.functions import is_subclass_int_not_bool
|
|
14
14
|
from utilities.iterables import one, one_str
|
15
15
|
from utilities.sentinel import ParseSentinelError, Sentinel, parse_sentinel
|
16
16
|
from utilities.text import ParseBoolError, ParseNoneError, parse_bool, parse_none
|
17
|
-
from utilities.typing import is_literal_type, is_optional_type
|
17
|
+
from utilities.typing import get_args, is_literal_type, is_optional_type
|
18
18
|
from utilities.version import ParseVersionError, Version, parse_version
|
19
19
|
|
20
20
|
|
utilities/polars.py
CHANGED
@@ -71,7 +71,6 @@ from utilities.iterables import (
|
|
71
71
|
CheckMappingsEqualError,
|
72
72
|
CheckSubSetError,
|
73
73
|
CheckSuperMappingError,
|
74
|
-
CheckSuperSetError,
|
75
74
|
OneEmptyError,
|
76
75
|
OneNonUniqueError,
|
77
76
|
always_iterable,
|
@@ -79,7 +78,6 @@ from utilities.iterables import (
|
|
79
78
|
check_mappings_equal,
|
80
79
|
check_subset,
|
81
80
|
check_supermapping,
|
82
|
-
check_superset,
|
83
81
|
is_iterable_not_str,
|
84
82
|
one,
|
85
83
|
)
|
@@ -92,7 +90,6 @@ from utilities.math import (
|
|
92
90
|
number_of_decimals,
|
93
91
|
)
|
94
92
|
from utilities.reprlib import get_repr
|
95
|
-
from utilities.sentinel import Sentinel
|
96
93
|
from utilities.types import MaybeStr, Number, WeekDay
|
97
94
|
from utilities.typing import (
|
98
95
|
get_args,
|
@@ -1484,100 +1481,6 @@ def week_num(column: IntoExprColumn, /, *, start: WeekDay = "mon") -> Expr | Ser
|
|
1484
1481
|
##
|
1485
1482
|
|
1486
1483
|
|
1487
|
-
def yield_rows_as_dataclasses(
|
1488
|
-
df: DataFrame,
|
1489
|
-
cls: type[TDataclass],
|
1490
|
-
/,
|
1491
|
-
*,
|
1492
|
-
globalns: StrMapping | None = None,
|
1493
|
-
localns: StrMapping | None = None,
|
1494
|
-
check_types: Literal["none", "first", "all"] = "first",
|
1495
|
-
) -> Iterator[TDataclass]:
|
1496
|
-
"""Yield the rows of a DataFrame as dataclasses."""
|
1497
|
-
from dacite import from_dict
|
1498
|
-
from dacite.exceptions import WrongTypeError
|
1499
|
-
|
1500
|
-
columns = df.columns
|
1501
|
-
required: set[str] = set()
|
1502
|
-
for field in yield_fields(cls, globalns=globalns, localns=localns):
|
1503
|
-
if isinstance(field.default, Sentinel) and isinstance(
|
1504
|
-
field.default_factory, Sentinel
|
1505
|
-
):
|
1506
|
-
required.add(field.name)
|
1507
|
-
try:
|
1508
|
-
check_superset(columns, required)
|
1509
|
-
except CheckSuperSetError as error:
|
1510
|
-
raise _YieldRowsAsDataClassesColumnsSuperSetError(
|
1511
|
-
df=df, cls=cls, left=error.left, right=error.right, extra=error.extra
|
1512
|
-
) from None
|
1513
|
-
rows = df.iter_rows(named=True)
|
1514
|
-
match check_types:
|
1515
|
-
case "none":
|
1516
|
-
yield from _yield_rows_as_dataclasses_no_check_types(rows, cls)
|
1517
|
-
case "first":
|
1518
|
-
try:
|
1519
|
-
first = next(rows)
|
1520
|
-
except StopIteration:
|
1521
|
-
return
|
1522
|
-
try:
|
1523
|
-
yield from_dict(cls, cast("Data", first))
|
1524
|
-
except WrongTypeError as error:
|
1525
|
-
raise _YieldRowsAsDataClassesWrongTypeError(
|
1526
|
-
df=df, cls=cls, msg=str(error)
|
1527
|
-
) from None
|
1528
|
-
yield from _yield_rows_as_dataclasses_no_check_types(rows, cls)
|
1529
|
-
case "all":
|
1530
|
-
try:
|
1531
|
-
for row in rows:
|
1532
|
-
yield from_dict(cls, cast("Data", row))
|
1533
|
-
except WrongTypeError as error:
|
1534
|
-
raise _YieldRowsAsDataClassesWrongTypeError(
|
1535
|
-
df=df, cls=cls, msg=str(error)
|
1536
|
-
) from None
|
1537
|
-
case _ as never:
|
1538
|
-
assert_never(never)
|
1539
|
-
|
1540
|
-
|
1541
|
-
def _yield_rows_as_dataclasses_no_check_types(
|
1542
|
-
rows: Iterator[dict[str, Any]], cls: type[TDataclass], /
|
1543
|
-
) -> Iterator[TDataclass]:
|
1544
|
-
"""Yield the rows of a DataFrame as dataclasses without type checking."""
|
1545
|
-
from dacite import Config, from_dict
|
1546
|
-
|
1547
|
-
config = Config(check_types=False)
|
1548
|
-
for row in rows:
|
1549
|
-
yield from_dict(cls, cast("Data", row), config=config)
|
1550
|
-
|
1551
|
-
|
1552
|
-
@dataclass(kw_only=True, slots=True)
|
1553
|
-
class YieldRowsAsDataClassesError(Exception):
|
1554
|
-
df: DataFrame
|
1555
|
-
cls: type[Dataclass]
|
1556
|
-
|
1557
|
-
|
1558
|
-
@dataclass(kw_only=True, slots=True)
|
1559
|
-
class _YieldRowsAsDataClassesColumnsSuperSetError(YieldRowsAsDataClassesError):
|
1560
|
-
left: AbstractSet[str]
|
1561
|
-
right: AbstractSet[str]
|
1562
|
-
extra: AbstractSet[str]
|
1563
|
-
|
1564
|
-
@override
|
1565
|
-
def __str__(self) -> str:
|
1566
|
-
return f"DataFrame columns {get_repr(self.left)} must be a superset of dataclass fields {get_repr(self.right)}; dataclass had extra fields {get_repr(self.extra)}."
|
1567
|
-
|
1568
|
-
|
1569
|
-
@dataclass(kw_only=True, slots=True)
|
1570
|
-
class _YieldRowsAsDataClassesWrongTypeError(YieldRowsAsDataClassesError):
|
1571
|
-
msg: str
|
1572
|
-
|
1573
|
-
@override
|
1574
|
-
def __str__(self) -> str:
|
1575
|
-
return self.msg
|
1576
|
-
|
1577
|
-
|
1578
|
-
##
|
1579
|
-
|
1580
|
-
|
1581
1484
|
@overload
|
1582
1485
|
def yield_struct_series_elements(
|
1583
1486
|
series: Series, /, *, strict: Literal[True]
|
@@ -1714,7 +1617,6 @@ __all__ = [
|
|
1714
1617
|
"IsNullStructSeriesError",
|
1715
1618
|
"SetFirstRowAsColumnsError",
|
1716
1619
|
"StructFromDataClassError",
|
1717
|
-
"YieldRowsAsDataClassesError",
|
1718
1620
|
"YieldStructSeriesElementsError",
|
1719
1621
|
"append_dataclass",
|
1720
1622
|
"are_frames_equal",
|
@@ -1749,7 +1651,6 @@ __all__ = [
|
|
1749
1651
|
"struct_from_dataclass",
|
1750
1652
|
"touch",
|
1751
1653
|
"unique_element",
|
1752
|
-
"yield_rows_as_dataclasses",
|
1753
1654
|
"yield_struct_series_dataclasses",
|
1754
1655
|
"yield_struct_series_elements",
|
1755
1656
|
"zoned_datetime",
|
File without changes
|
File without changes
|