dycw-utilities 0.159.1__py3-none-any.whl → 0.159.3__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.159.1
3
+ Version: 0.159.3
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=Sn6930zXuSe3WGJ5qrzIW92IebaarjXcUx0osmO7Hsk,60
1
+ utilities/__init__.py,sha256=VdqkGeeq4rCnCdHuCDKZa_vNmpgPYng4SgWvMihfJwo,60
2
2
  utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
3
3
  utilities/asyncio.py,sha256=PUedzQ5deqlSECQ33sam9cRzI9TnygHz3FdOqWJWPTM,15288
4
4
  utilities/atomicwrites.py,sha256=tPo6r-Rypd9u99u66B9z86YBPpnLrlHtwox_8Z7T34Y,5790
@@ -45,7 +45,7 @@ utilities/parse.py,sha256=JcJn5yXKhIWXBCwgBdPsyu7Hvcuw6kyEdqvaebCaI9k,17951
45
45
  utilities/pathlib.py,sha256=qGuU8XPmdgGpy8tOMUgelfXx3kxI8h9IaV3TI_06QGE,8428
46
46
  utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
47
47
  utilities/platform.py,sha256=pTn7gw6N4T6LdKrf0virwarof_mze9WtoQlrGMzhGVI,2798
48
- utilities/polars.py,sha256=qgk9TXHrHodUsgevDbtglYtiZ8jZ-PT8y4EyfU4fk9U,76772
48
+ utilities/polars.py,sha256=_pQS5wmtkMgu5CZZKDVA4AnT6NyLSlYKe5GK6hBR7vU,77876
49
49
  utilities/polars_ols.py,sha256=Uc9V5kvlWZ5cU93lKZ-cfAKdVFFw81tqwLW9PxtUvMs,5618
50
50
  utilities/postgres.py,sha256=ynCTTaF-bVEOSW-KEAR-dlLh_hYjeVVjm__-4pEU8Zk,12269
51
51
  utilities/pottery.py,sha256=ggMN72Y7wx7Js8VN6eyNyodpm8TIYqZHGghkDPXIVWk,3949
@@ -74,7 +74,7 @@ utilities/threading.py,sha256=GvBOp4CyhHfN90wGXZuA2VKe9fGzMaEa7oCl4f3nnPU,1009
74
74
  utilities/timer.py,sha256=oXfTii6ymu57niP0BDGZjFD55LEHi2a19kqZKiTgaFQ,2588
75
75
  utilities/traceback.py,sha256=1k5JgumSMaqAGLd0dZ36CtPS0EGaglxTr29r2Dz4D60,9457
76
76
  utilities/typed_settings.py,sha256=SFWqS3lAzV7IfNRwqFcTk0YynTcQ7BmrcW2mr_KUnos,4466
77
- utilities/types.py,sha256=L4cjFPyFZX58Urfw0S_i-XRywPIFyuSLOieewj0qqsM,18516
77
+ utilities/types.py,sha256=zVMapJd3i6xPrY4VagawVfBW_a-ygIKWffwXqxcH0bo,18604
78
78
  utilities/typing.py,sha256=7ZgCNZwA6oaiwpSJIS9Rj3i3MbRBYHMqbC3jMe5KiNg,13992
79
79
  utilities/tzdata.py,sha256=fgNVj66yUbCSI_-vrRVzSD3gtf-L_8IEJEPjP_Jel5Y,266
80
80
  utilities/tzlocal.py,sha256=KyCXEgCTjqGFx-389JdTuhMRUaT06U1RCMdWoED-qro,728
@@ -87,8 +87,8 @@ utilities/zoneinfo.py,sha256=FBMcUQ4662Aq8SsuCL1OAhDQiyANmVjtb-C30DRrWoE,1966
87
87
  utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
88
88
  utilities/pytest_plugins/pytest_randomly.py,sha256=B1qYVlExGOxTywq2r1SMi5o7btHLk2PNdY_b1p98dkE,409
89
89
  utilities/pytest_plugins/pytest_regressions.py,sha256=9v8kAXDM2ycIXJBimoiF4EgrwbUvxTycFWJiGR_GHhM,1466
90
- dycw_utilities-0.159.1.dist-info/METADATA,sha256=CxCbx_EE_zO3iemn0g8u__516dCh1gbwoQCSZZ7ZEcE,1643
91
- dycw_utilities-0.159.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
- dycw_utilities-0.159.1.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
93
- dycw_utilities-0.159.1.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
94
- dycw_utilities-0.159.1.dist-info/RECORD,,
90
+ dycw_utilities-0.159.3.dist-info/METADATA,sha256=vx1O7lyZWHV89NyvhKldxK9kl_d9wpawar1WayIcveA,1643
91
+ dycw_utilities-0.159.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
+ dycw_utilities-0.159.3.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
93
+ dycw_utilities-0.159.3.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
94
+ dycw_utilities-0.159.3.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.159.1"
3
+ __version__ = "0.159.3"
utilities/polars.py CHANGED
@@ -32,9 +32,11 @@ from polars import (
32
32
  any_horizontal,
33
33
  col,
34
34
  concat,
35
+ concat_list,
35
36
  datetime_range,
36
37
  int_range,
37
38
  lit,
39
+ max_horizontal,
38
40
  struct,
39
41
  sum_horizontal,
40
42
  when,
@@ -1323,6 +1325,15 @@ class _FiniteEWMWeightsError(Exception):
1323
1325
  ##
1324
1326
 
1325
1327
 
1328
+ def first_true_horizontal(df: DataFrame, /) -> Series:
1329
+ """Get the index of the first true in each row."""
1330
+ expr = when(any_horizontal(pl.all())).then(concat_list(pl.all()).list.arg_max())
1331
+ return one_column(df.select(expr))
1332
+
1333
+
1334
+ ##
1335
+
1336
+
1326
1337
  def get_data_type_or_series_time_zone(
1327
1338
  dtype_or_series: PolarsDataType | Series, /
1328
1339
  ) -> ZoneInfo:
@@ -1631,6 +1642,42 @@ def integers(
1631
1642
  ##
1632
1643
 
1633
1644
 
1645
+ @overload
1646
+ def is_close(
1647
+ x: ExprLike, y: ExprLike, /, *, rel_tol: float = 1e-9, abs_tol: float = 0
1648
+ ) -> Expr: ...
1649
+ @overload
1650
+ def is_close(
1651
+ x: Series, y: Series, /, *, rel_tol: float = 1e-9, abs_tol: float = 0
1652
+ ) -> Series: ...
1653
+ @overload
1654
+ def is_close(
1655
+ x: IntoExprColumn,
1656
+ y: IntoExprColumn,
1657
+ /,
1658
+ *,
1659
+ rel_tol: float = 1e-9,
1660
+ abs_tol: float = 0,
1661
+ ) -> ExprOrSeries: ...
1662
+ def is_close(
1663
+ x: IntoExprColumn,
1664
+ y: IntoExprColumn,
1665
+ /,
1666
+ *,
1667
+ rel_tol: float = 1e-9,
1668
+ abs_tol: float = 0,
1669
+ ) -> ExprOrSeries:
1670
+ """Check if two columns are close."""
1671
+ x, y = map(ensure_expr_or_series, [x, y])
1672
+ result = (x - y).abs() <= max_horizontal(
1673
+ rel_tol * max_horizontal(x.abs(), y.abs()), abs_tol
1674
+ )
1675
+ return try_reify_expr(result, x, y)
1676
+
1677
+
1678
+ ##
1679
+
1680
+
1634
1681
  @overload
1635
1682
  def is_near_event(
1636
1683
  *exprs: ExprLike, before: int = 0, after: int = 0, **named_exprs: ExprLike
@@ -2583,6 +2630,7 @@ __all__ = [
2583
2630
  "ensure_expr_or_series_many",
2584
2631
  "expr_to_series",
2585
2632
  "finite_ewm_mean",
2633
+ "first_true_horizontal",
2586
2634
  "get_data_type_or_series_time_zone",
2587
2635
  "get_expr_name",
2588
2636
  "get_frequency_spectrum",
@@ -2592,6 +2640,7 @@ __all__ = [
2592
2640
  "insert_before",
2593
2641
  "insert_between",
2594
2642
  "integers",
2643
+ "is_close",
2595
2644
  "is_false",
2596
2645
  "is_near_event",
2597
2646
  "is_true",
utilities/types.py CHANGED
@@ -79,6 +79,9 @@ type MaybeCoro[T] = T | Coro[T]
79
79
 
80
80
 
81
81
  # collections.abc
82
+ type SupportsFloatOrIndex = SupportsFloat | SupportsIndex
83
+
84
+
82
85
  @runtime_checkable
83
86
  class SupportsKeysAndGetItem(Protocol[_T, _T_co]):
84
87
  def keys(self) -> Iterable[_T]: ... # pragma: no cover
@@ -328,6 +331,7 @@ __all__ = [
328
331
  "SupportsBytes",
329
332
  "SupportsComplex",
330
333
  "SupportsFloat",
334
+ "SupportsFloatOrIndex",
331
335
  "SupportsGT",
332
336
  "SupportsInt",
333
337
  "SupportsInt",