dycw-utilities 0.153.3__py3-none-any.whl → 0.153.5__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.153.3
3
+ Version: 0.153.5
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=1GHQrcKaEUZf3pfIY7NBsyrMxgkxqFe8199dJVber6A,60
1
+ utilities/__init__.py,sha256=UKnoBPsvjUBIqzHxpYFxmj-sB445m7ZiCPW-H1lVF5k,60
2
2
  utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
3
3
  utilities/asyncio.py,sha256=QXkTtugXkqtYt7Do23zgYErqzdp6jwzPpV_SP9fJ1gI,16780
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=Ba1XxJZ3Q8i_mHkcNxjo4aGuMKwRsCdh0mIDI-V_HXw,76581
48
+ utilities/polars.py,sha256=jNUs038dJMZ0-r3rmHFClIzHlx3naA9klgYBvRDJi9w,77738
49
49
  utilities/polars_ols.py,sha256=Uc9V5kvlWZ5cU93lKZ-cfAKdVFFw81tqwLW9PxtUvMs,5618
50
50
  utilities/postgres.py,sha256=70BPcb_Na0LqDXJfqu0JwkHkGrwyuKpIVooSm6NlRn8,12467
51
51
  utilities/pottery.py,sha256=HJ96oLRarTP37Vhg0WTyB3yAu2hETeg6HgRmpDIqyUs,6581
@@ -74,7 +74,7 @@ utilities/threading.py,sha256=GvBOp4CyhHfN90wGXZuA2VKe9fGzMaEa7oCl4f3nnPU,1009
74
74
  utilities/timer.py,sha256=oXfTii6ymu57niP0BDGZjFD55LEHi2a19kqZKiTgaFQ,2588
75
75
  utilities/traceback.py,sha256=e0BpxNMybVmELHGsYM5N6LVbfmn0jLhefLoa81NjZBg,9100
76
76
  utilities/typed_settings.py,sha256=SFWqS3lAzV7IfNRwqFcTk0YynTcQ7BmrcW2mr_KUnos,4466
77
- utilities/types.py,sha256=SE5UTkI7EVdg_gVehgn9fRQ7TAOi2C1LpEm8qLIhZcs,18455
77
+ utilities/types.py,sha256=L4cjFPyFZX58Urfw0S_i-XRywPIFyuSLOieewj0qqsM,18516
78
78
  utilities/typing.py,sha256=Z-_XDaWyT_6wIo3qfNK-hvRlzxP2Jxa9PgXzm5rDYRA,13790
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.153.3.dist-info/METADATA,sha256=xSL1sIennAtafYoihcSuowIbjg7Wywuh9l5u3kLM7qg,1696
91
- dycw_utilities-0.153.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
- dycw_utilities-0.153.3.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
93
- dycw_utilities-0.153.3.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
94
- dycw_utilities-0.153.3.dist-info/RECORD,,
90
+ dycw_utilities-0.153.5.dist-info/METADATA,sha256=fdVY9p8qoujQ4PkOgQ_lgFeSkK-HItBHJYsi-nd_4Bo,1696
91
+ dycw_utilities-0.153.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
+ dycw_utilities-0.153.5.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
93
+ dycw_utilities-0.153.5.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
94
+ dycw_utilities-0.153.5.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.153.3"
3
+ __version__ = "0.153.5"
utilities/polars.py CHANGED
@@ -124,6 +124,7 @@ if TYPE_CHECKING:
124
124
 
125
125
 
126
126
  type ExprLike = MaybeStr[Expr]
127
+ type ExprOrSeries = Expr | Series
127
128
  DatetimeHongKong = Datetime(time_zone="Asia/Hong_Kong")
128
129
  DatetimeTokyo = Datetime(time_zone="Asia/Tokyo")
129
130
  DatetimeUSCentral = Datetime(time_zone="US/Central")
@@ -241,11 +242,6 @@ def _acf_process_qstats_pvalues(qstats: NDArrayF, pvalues: NDArrayF, /) -> DataF
241
242
  ##
242
243
 
243
244
 
244
- # def acf_halflife(series: Series,/)
245
-
246
- ##
247
-
248
-
249
245
  def adjust_frequencies(
250
246
  series: Series,
251
247
  /,
@@ -267,6 +263,37 @@ def adjust_frequencies(
267
263
  ##
268
264
 
269
265
 
266
+ def all_dataframe_columns(
267
+ df: DataFrame, expr: IntoExprColumn, /, *exprs: IntoExprColumn
268
+ ) -> Series:
269
+ """Return a DataFrame column with `AND` applied to additional exprs/series."""
270
+ name = get_expr_name(df, expr)
271
+ return df.select(all_horizontal(expr, *exprs).alias(name))[name]
272
+
273
+
274
+ def any_dataframe_columns(
275
+ df: DataFrame, expr: IntoExprColumn, /, *exprs: IntoExprColumn
276
+ ) -> Series:
277
+ """Return a DataFrame column with `OR` applied to additional exprs/series."""
278
+ name = get_expr_name(df, expr)
279
+ return df.select(any_horizontal(expr, *exprs).alias(name))[name]
280
+
281
+
282
+ def all_series(series: Series, /, *columns: ExprOrSeries) -> Series:
283
+ """Return a Series with `AND` applied to additional exprs/series."""
284
+ return all_dataframe_columns(series.to_frame(), series.name, *columns)
285
+
286
+
287
+ def any_series(series: Series, /, *columns: ExprOrSeries) -> Series:
288
+ """Return a Series with `OR` applied to additional exprs/series."""
289
+ df = series.to_frame()
290
+ name = series.name
291
+ return df.select(any_horizontal(name, *columns).alias(name))[name]
292
+
293
+
294
+ ##
295
+
296
+
270
297
  def append_dataclass(df: DataFrame, obj: Dataclass, /) -> DataFrame:
271
298
  """Append a dataclass object to a DataFrame."""
272
299
  non_null_fields = {k: v for k, v in asdict(obj).items() if v is not None}
@@ -430,8 +457,8 @@ def ceil_datetime(column: ExprLike, every: ExprLike, /) -> Expr: ...
430
457
  @overload
431
458
  def ceil_datetime(column: Series, every: ExprLike, /) -> Series: ...
432
459
  @overload
433
- def ceil_datetime(column: IntoExprColumn, every: ExprLike, /) -> Expr | Series: ...
434
- def ceil_datetime(column: IntoExprColumn, every: ExprLike, /) -> Expr | Series:
460
+ def ceil_datetime(column: IntoExprColumn, every: ExprLike, /) -> ExprOrSeries: ...
461
+ def ceil_datetime(column: IntoExprColumn, every: ExprLike, /) -> ExprOrSeries:
435
462
  """Compute the `ceil` of a datetime column."""
436
463
  column = ensure_expr_or_series(column)
437
464
  rounded = column.dt.round(every)
@@ -852,13 +879,13 @@ def cross(
852
879
  up_or_down: Literal["up", "down"],
853
880
  other: Number | IntoExprColumn,
854
881
  /,
855
- ) -> Expr | Series: ...
882
+ ) -> ExprOrSeries: ...
856
883
  def cross(
857
884
  expr: IntoExprColumn,
858
885
  up_or_down: Literal["up", "down"],
859
886
  other: Number | IntoExprColumn,
860
887
  /,
861
- ) -> Expr | Series:
888
+ ) -> ExprOrSeries:
862
889
  """Compute when a cross occurs."""
863
890
  return _cross_or_touch(expr, "cross", up_or_down, other)
864
891
 
@@ -877,13 +904,13 @@ def touch(
877
904
  up_or_down: Literal["up", "down"],
878
905
  other: Number | IntoExprColumn,
879
906
  /,
880
- ) -> Expr | Series: ...
907
+ ) -> ExprOrSeries: ...
881
908
  def touch(
882
909
  expr: IntoExprColumn,
883
910
  up_or_down: Literal["up", "down"],
884
911
  other: Number | IntoExprColumn,
885
912
  /,
886
- ) -> Expr | Series:
913
+ ) -> ExprOrSeries:
887
914
  """Compute when a touch occurs."""
888
915
  return _cross_or_touch(expr, "touch", up_or_down, other)
889
916
 
@@ -894,7 +921,7 @@ def _cross_or_touch(
894
921
  up_or_down: Literal["up", "down"],
895
922
  other: Number | IntoExprColumn,
896
923
  /,
897
- ) -> Expr | Series:
924
+ ) -> ExprOrSeries:
898
925
  """Compute when a column crosses/touches a threshold."""
899
926
  expr = ensure_expr_or_series(expr)
900
927
  match other:
@@ -966,7 +993,7 @@ def cross_rolling_quantile(
966
993
  weights: list[float] | None = None,
967
994
  min_samples: int | None = None,
968
995
  center: bool = False,
969
- ) -> Expr | Series: ...
996
+ ) -> ExprOrSeries: ...
970
997
  def cross_rolling_quantile(
971
998
  expr: IntoExprColumn,
972
999
  up_or_down: Literal["up", "down"],
@@ -978,7 +1005,7 @@ def cross_rolling_quantile(
978
1005
  weights: list[float] | None = None,
979
1006
  min_samples: int | None = None,
980
1007
  center: bool = False,
981
- ) -> Expr | Series:
1008
+ ) -> ExprOrSeries:
982
1009
  """Compute when a column crosses its rolling quantile."""
983
1010
  expr = ensure_expr_or_series(expr)
984
1011
  rolling = expr.rolling_quantile(
@@ -1183,8 +1210,8 @@ def ensure_expr_or_series(column: ExprLike, /) -> Expr: ...
1183
1210
  @overload
1184
1211
  def ensure_expr_or_series(column: Series, /) -> Series: ...
1185
1212
  @overload
1186
- def ensure_expr_or_series(column: IntoExprColumn, /) -> Expr | Series: ...
1187
- def ensure_expr_or_series(column: IntoExprColumn, /) -> Expr | Series:
1213
+ def ensure_expr_or_series(column: IntoExprColumn, /) -> ExprOrSeries: ...
1214
+ def ensure_expr_or_series(column: IntoExprColumn, /) -> ExprOrSeries:
1188
1215
  """Ensure a column expression or Series is returned."""
1189
1216
  return col(column) if isinstance(column, str) else column
1190
1217
 
@@ -1194,7 +1221,7 @@ def ensure_expr_or_series(column: IntoExprColumn, /) -> Expr | Series:
1194
1221
 
1195
1222
  def ensure_expr_or_series_many(
1196
1223
  *columns: IntoExprColumn, **named_columns: IntoExprColumn
1197
- ) -> Sequence[Expr | Series]:
1224
+ ) -> Sequence[ExprOrSeries]:
1198
1225
  """Ensure a set of column expressions and/or Series are returned."""
1199
1226
  args = map(ensure_expr_or_series, columns)
1200
1227
  kwargs = (ensure_expr_or_series(v).alias(k) for k, v in named_columns.items())
@@ -1236,7 +1263,7 @@ def finite_ewm_mean(
1236
1263
  half_life: float | None = None,
1237
1264
  alpha: float | None = None,
1238
1265
  min_weight: float = _FINITE_EWM_MIN_WEIGHT,
1239
- ) -> Expr | Series: ...
1266
+ ) -> ExprOrSeries: ...
1240
1267
  def finite_ewm_mean(
1241
1268
  column: IntoExprColumn,
1242
1269
  /,
@@ -1246,7 +1273,7 @@ def finite_ewm_mean(
1246
1273
  half_life: float | None = None,
1247
1274
  alpha: float | None = None,
1248
1275
  min_weight: float = _FINITE_EWM_MIN_WEIGHT,
1249
- ) -> Expr | Series:
1276
+ ) -> ExprOrSeries:
1250
1277
  """Compute a finite EWMA."""
1251
1278
  try:
1252
1279
  weights = _finite_ewm_weights(
@@ -1312,8 +1339,8 @@ def floor_datetime(column: ExprLike, every: ExprLike, /) -> Expr: ...
1312
1339
  @overload
1313
1340
  def floor_datetime(column: Series, every: ExprLike, /) -> Series: ...
1314
1341
  @overload
1315
- def floor_datetime(column: IntoExprColumn, every: ExprLike, /) -> Expr | Series: ...
1316
- def floor_datetime(column: IntoExprColumn, every: ExprLike, /) -> Expr | Series:
1342
+ def floor_datetime(column: IntoExprColumn, every: ExprLike, /) -> ExprOrSeries: ...
1343
+ def floor_datetime(column: IntoExprColumn, every: ExprLike, /) -> ExprOrSeries:
1317
1344
  """Compute the `floor` of a datetime column."""
1318
1345
  column = ensure_expr_or_series(column)
1319
1346
  rounded = column.dt.round(every)
@@ -1479,8 +1506,8 @@ def increasing_horizontal(*columns: ExprLike) -> Expr: ...
1479
1506
  @overload
1480
1507
  def increasing_horizontal(*columns: Series) -> Series: ...
1481
1508
  @overload
1482
- def increasing_horizontal(*columns: IntoExprColumn) -> Expr | Series: ...
1483
- def increasing_horizontal(*columns: IntoExprColumn) -> Expr | Series:
1509
+ def increasing_horizontal(*columns: IntoExprColumn) -> ExprOrSeries: ...
1510
+ def increasing_horizontal(*columns: IntoExprColumn) -> ExprOrSeries:
1484
1511
  """Check if a set of columns are increasing."""
1485
1512
  columns2 = ensure_expr_or_series_many(*columns)
1486
1513
  if len(columns2) == 0:
@@ -1493,8 +1520,8 @@ def decreasing_horizontal(*columns: ExprLike) -> Expr: ...
1493
1520
  @overload
1494
1521
  def decreasing_horizontal(*columns: Series) -> Series: ...
1495
1522
  @overload
1496
- def decreasing_horizontal(*columns: IntoExprColumn) -> Expr | Series: ...
1497
- def decreasing_horizontal(*columns: IntoExprColumn) -> Expr | Series:
1523
+ def decreasing_horizontal(*columns: IntoExprColumn) -> ExprOrSeries: ...
1524
+ def decreasing_horizontal(*columns: IntoExprColumn) -> ExprOrSeries:
1498
1525
  """Check if a set of columns are decreasing."""
1499
1526
  columns2 = ensure_expr_or_series_many(*columns)
1500
1527
  if len(columns2) == 0:
@@ -1653,13 +1680,13 @@ def is_near_event(
1653
1680
  before: int = 0,
1654
1681
  after: int = 0,
1655
1682
  **named_exprs: IntoExprColumn,
1656
- ) -> Expr | Series: ...
1683
+ ) -> ExprOrSeries: ...
1657
1684
  def is_near_event(
1658
1685
  *exprs: IntoExprColumn,
1659
1686
  before: int = 0,
1660
1687
  after: int = 0,
1661
1688
  **named_exprs: IntoExprColumn,
1662
- ) -> Expr | Series:
1689
+ ) -> ExprOrSeries:
1663
1690
  """Compute the rows near any event."""
1664
1691
  if before <= -1:
1665
1692
  raise _IsNearEventBeforeError(before=before)
@@ -2044,10 +2071,10 @@ def order_of_magnitude(column: Series, /, *, round_: bool = False) -> Series: ..
2044
2071
  @overload
2045
2072
  def order_of_magnitude(
2046
2073
  column: IntoExprColumn, /, *, round_: bool = False
2047
- ) -> Expr | Series: ...
2074
+ ) -> ExprOrSeries: ...
2048
2075
  def order_of_magnitude(
2049
2076
  column: IntoExprColumn, /, *, round_: bool = False
2050
- ) -> Expr | Series:
2077
+ ) -> ExprOrSeries:
2051
2078
  """Compute the order of magnitude of a column."""
2052
2079
  column = ensure_expr_or_series(column)
2053
2080
  result = column.abs().log10()
@@ -2448,7 +2475,7 @@ class _StructFromDataClassTypeError(StructFromDataClassError):
2448
2475
 
2449
2476
  def try_reify_expr(
2450
2477
  expr: IntoExprColumn, /, *exprs: IntoExprColumn, **named_exprs: IntoExprColumn
2451
- ) -> Expr | Series:
2478
+ ) -> ExprOrSeries:
2452
2479
  """Try reify an expression."""
2453
2480
  expr = ensure_expr_or_series(expr)
2454
2481
  all_exprs = ensure_expr_or_series_many(*exprs, **named_exprs)
@@ -2515,8 +2542,8 @@ def week_num(column: ExprLike, /, *, start: WeekDay = "mon") -> Expr: ...
2515
2542
  @overload
2516
2543
  def week_num(column: Series, /, *, start: WeekDay = "mon") -> Series: ...
2517
2544
  @overload
2518
- def week_num(column: IntoExprColumn, /, *, start: WeekDay = "mon") -> Expr | Series: ...
2519
- def week_num(column: IntoExprColumn, /, *, start: WeekDay = "mon") -> Expr | Series:
2545
+ def week_num(column: IntoExprColumn, /, *, start: WeekDay = "mon") -> ExprOrSeries: ...
2546
+ def week_num(column: IntoExprColumn, /, *, start: WeekDay = "mon") -> ExprOrSeries:
2520
2547
  """Compute the week number of a date column."""
2521
2548
  column = ensure_expr_or_series(column)
2522
2549
  epoch = column.dt.epoch(time_unit="d").alias("epoch")
@@ -2562,6 +2589,7 @@ __all__ = [
2562
2589
  "DatetimeUSEastern",
2563
2590
  "DatetimeUTC",
2564
2591
  "DropNullStructSeriesError",
2592
+ "ExprOrSeries",
2565
2593
  "FiniteEWMMeanError",
2566
2594
  "GetDataTypeOrSeriesTimeZoneError",
2567
2595
  "GetSeriesNumberOfDecimalsError",
@@ -2574,6 +2602,10 @@ __all__ = [
2574
2602
  "StructFromDataClassError",
2575
2603
  "acf",
2576
2604
  "adjust_frequencies",
2605
+ "all_dataframe_columns",
2606
+ "all_series",
2607
+ "any_dataframe_columns",
2608
+ "any_series",
2577
2609
  "append_dataclass",
2578
2610
  "are_frames_equal",
2579
2611
  "bernoulli",
utilities/types.py CHANGED
@@ -118,6 +118,7 @@ IPv6AddressLike = MaybeStr[IPv6Address]
118
118
  type MaybeCollection[T] = T | Collection[T]
119
119
  type MaybeIterable[T] = T | Iterable[T]
120
120
  type MaybeList[T] = T | list[T]
121
+ type MaybeSet[T] = T | set[T] | frozenset[T]
121
122
  type SequenceLT[T] = list[T] | tuple[T, ...]
122
123
  # iterables - dervied
123
124
  type MaybeSequence[T] = T | SequenceLT[T]
@@ -303,6 +304,7 @@ __all__ = [
303
304
  "MaybeList",
304
305
  "MaybeSequence",
305
306
  "MaybeSequenceStr",
307
+ "MaybeSet",
306
308
  "MaybeStr",
307
309
  "MaybeType",
308
310
  "MonthDayLike",