dycw-utilities 0.150.13__py3-none-any.whl → 0.150.14__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.150.13
3
+ Version: 0.150.14
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=Dso32ACb66Psk-daIQDsHv_bmVx1YtOxzv9SWRzvkOk,61
1
+ utilities/__init__.py,sha256=bT5xIpzoPlIVlbwQr1301PGD5JrP7I8LD4yJhFWChD4,61
2
2
  utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
3
3
  utilities/asyncio.py,sha256=2m2a2C-Qgc6OHTTHL332-t66A7xDITt_SORT7a1DJWo,16792
4
4
  utilities/atomicwrites.py,sha256=xcOWenTBRS0oat3kg7Sqe51AohNThMQ2ixPL7QCG8hw,5795
@@ -66,7 +66,7 @@ utilities/sentinel.py,sha256=3jIwgpMekWgDAxPDA_hXMP2St43cPhciKN3LWiZ7kv0,1248
66
66
  utilities/shelve.py,sha256=4OzjQI6kGuUbJciqf535rwnao-_IBv66gsT6tRGiUt0,759
67
67
  utilities/slack_sdk.py,sha256=ppFBvKgfg5IRWiIoKPtpTyzBtBF4XmwEvU3I5wLJikM,2140
68
68
  utilities/socket.py,sha256=K77vfREvzoVTrpYKo6MZakol0EYu2q1sWJnnZqL0So0,118
69
- utilities/sqlalchemy.py,sha256=PVQXLRXPvULmGpKaa21lM21fUDzEIcqx_-d5oQFdD8A,39610
69
+ utilities/sqlalchemy.py,sha256=QbCFKefrkkqL23iDF5WdOKRfISMj6c-SyrI3rvBATE4,39641
70
70
  utilities/sqlalchemy_polars.py,sha256=18AoEbeNJUKF3-5hroNy9J5LQwS_QJAXbMfKc9sChtk,14250
71
71
  utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
72
72
  utilities/string.py,sha256=MB0X6UPTUc06JdAdj-PctZ238IXeCjE5dAJibNw6ZrU,587
@@ -89,8 +89,8 @@ utilities/zoneinfo.py,sha256=oEH-nL3t4h9uawyZqWDtNtDAl6M-CLpLYGI_nI6DulM,1971
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.150.13.dist-info/METADATA,sha256=WnT6T9ZLZ13ELERVuzIbh3HGGjn9pDj0_JVykzsUezs,1697
93
- dycw_utilities-0.150.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
- dycw_utilities-0.150.13.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
95
- dycw_utilities-0.150.13.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
96
- dycw_utilities-0.150.13.dist-info/RECORD,,
92
+ dycw_utilities-0.150.14.dist-info/METADATA,sha256=qROpqych2gxzNw7cNMeSkurdfRUA6V1ivBjBeNA9JUk,1697
93
+ dycw_utilities-0.150.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
+ dycw_utilities-0.150.14.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
95
+ dycw_utilities-0.150.14.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
96
+ dycw_utilities-0.150.14.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.150.13"
3
+ __version__ = "0.150.14"
utilities/sqlalchemy.py CHANGED
@@ -97,12 +97,17 @@ from utilities.iterables import (
97
97
  )
98
98
  from utilities.reprlib import get_repr
99
99
  from utilities.text import secret_str, snake_case
100
- from utilities.types import MaybeIterable, MaybeType, StrMapping, TupleOrStrMapping
100
+ from utilities.types import (
101
+ Delta,
102
+ MaybeIterable,
103
+ MaybeType,
104
+ StrMapping,
105
+ TupleOrStrMapping,
106
+ )
101
107
 
102
108
  if TYPE_CHECKING:
103
109
  from enum import Enum, StrEnum
104
110
 
105
- from whenever import TimeDelta
106
111
 
107
112
  type EngineOrConnectionOrAsync = Engine | Connection | AsyncEngine | AsyncConnection
108
113
  type Dialect = Literal["mssql", "mysql", "oracle", "postgresql", "sqlite"]
@@ -127,12 +132,14 @@ def check_connect(engine: Engine, /) -> bool:
127
132
  return False
128
133
 
129
134
 
130
- async def check_connect_async(engine: AsyncEngine, /) -> bool:
135
+ async def check_connect_async(
136
+ engine: AsyncEngine, /, *, timeout: Delta | None = None
137
+ ) -> bool:
131
138
  """Check if an engine can connect."""
132
139
  try:
133
- async with engine.connect() as conn:
140
+ async with timeout_td(timeout), engine.connect() as conn:
134
141
  return bool((await conn.execute(_SELECT)).scalar_one())
135
- except (OperationalError, ProgrammingError):
142
+ except (OperationalError, ProgrammingError, TimeoutError):
136
143
  return False
137
144
 
138
145
 
@@ -143,7 +150,7 @@ async def check_engine(
143
150
  engine: AsyncEngine,
144
151
  /,
145
152
  *,
146
- timeout: TimeDelta | None = None,
153
+ timeout: Delta | None = None,
147
154
  error: type[Exception] = TimeoutError,
148
155
  num_tables: int | tuple[int, float] | None = None,
149
156
  ) -> None:
@@ -316,7 +323,7 @@ async def ensure_tables_created(
316
323
  engine: AsyncEngine,
317
324
  /,
318
325
  *tables_or_orms: TableOrORMInstOrClass,
319
- timeout: TimeDelta | None = None,
326
+ timeout: Delta | None = None,
320
327
  error: type[Exception] = TimeoutError,
321
328
  ) -> None:
322
329
  """Ensure a table/set of tables is/are created."""
@@ -345,7 +352,7 @@ async def ensure_tables_created(
345
352
  async def ensure_tables_dropped(
346
353
  engine: AsyncEngine,
347
354
  *tables_or_orms: TableOrORMInstOrClass,
348
- timeout: TimeDelta | None = None,
355
+ timeout: Delta | None = None,
349
356
  error: type[Exception] = TimeoutError,
350
357
  ) -> None:
351
358
  """Ensure a table/set of tables is/are dropped."""
@@ -575,9 +582,9 @@ async def insert_items(
575
582
  snake: bool = False,
576
583
  chunk_size_frac: float = CHUNK_SIZE_FRAC,
577
584
  assume_tables_exist: bool = False,
578
- timeout_create: TimeDelta | None = None,
585
+ timeout_create: Delta | None = None,
579
586
  error_create: type[Exception] = TimeoutError,
580
- timeout_insert: TimeDelta | None = None,
587
+ timeout_insert: Delta | None = None,
581
588
  error_insert: type[Exception] = TimeoutError,
582
589
  ) -> None:
583
590
  """Insert a set of items into a database.
@@ -676,9 +683,9 @@ async def migrate_data(
676
683
  table_or_orm_to: TableOrORMInstOrClass | None = None,
677
684
  chunk_size_frac: float = CHUNK_SIZE_FRAC,
678
685
  assume_tables_exist: bool = False,
679
- timeout_create: TimeDelta | None = None,
686
+ timeout_create: Delta | None = None,
680
687
  error_create: type[Exception] = TimeoutError,
681
- timeout_insert: TimeDelta | None = None,
688
+ timeout_insert: Delta | None = None,
682
689
  error_insert: type[Exception] = TimeoutError,
683
690
  ) -> None:
684
691
  """Migrate the contents of a table from one database to another."""
@@ -812,9 +819,9 @@ async def upsert_items(
812
819
  selected_or_all: _SelectedOrAll = "selected",
813
820
  chunk_size_frac: float = CHUNK_SIZE_FRAC,
814
821
  assume_tables_exist: bool = False,
815
- timeout_create: TimeDelta | None = None,
822
+ timeout_create: Delta | None = None,
816
823
  error_create: type[Exception] = TimeoutError,
817
- timeout_insert: TimeDelta | None = None,
824
+ timeout_insert: Delta | None = None,
818
825
  error_insert: type[Exception] = TimeoutError,
819
826
  ) -> None:
820
827
  """Upsert a set of items into a database.
@@ -934,7 +941,7 @@ async def yield_connection(
934
941
  engine: AsyncEngine,
935
942
  /,
936
943
  *,
937
- timeout: TimeDelta | None = None,
944
+ timeout: Delta | None = None,
938
945
  error: MaybeType[BaseException] = TimeoutError,
939
946
  ) -> AsyncIterator[AsyncConnection]:
940
947
  """Yield an async connection."""