polars-runtime-compat 1.34.0b2__cp39-abi3-manylinux_2_24_aarch64.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.

Potentially problematic release.


This version of polars-runtime-compat might be problematic. Click here for more details.

Files changed (203) hide show
  1. _polars_runtime_compat/.gitkeep +0 -0
  2. _polars_runtime_compat/_polars_runtime_compat.abi3.so +0 -0
  3. polars/__init__.py +528 -0
  4. polars/_cpu_check.py +265 -0
  5. polars/_dependencies.py +355 -0
  6. polars/_plr.py +99 -0
  7. polars/_plr.pyi +2496 -0
  8. polars/_reexport.py +23 -0
  9. polars/_typing.py +478 -0
  10. polars/_utils/__init__.py +37 -0
  11. polars/_utils/async_.py +102 -0
  12. polars/_utils/cache.py +176 -0
  13. polars/_utils/cloud.py +40 -0
  14. polars/_utils/constants.py +29 -0
  15. polars/_utils/construction/__init__.py +46 -0
  16. polars/_utils/construction/dataframe.py +1397 -0
  17. polars/_utils/construction/other.py +72 -0
  18. polars/_utils/construction/series.py +560 -0
  19. polars/_utils/construction/utils.py +118 -0
  20. polars/_utils/convert.py +224 -0
  21. polars/_utils/deprecation.py +406 -0
  22. polars/_utils/getitem.py +457 -0
  23. polars/_utils/logging.py +11 -0
  24. polars/_utils/nest_asyncio.py +264 -0
  25. polars/_utils/parquet.py +15 -0
  26. polars/_utils/parse/__init__.py +12 -0
  27. polars/_utils/parse/expr.py +242 -0
  28. polars/_utils/polars_version.py +19 -0
  29. polars/_utils/pycapsule.py +53 -0
  30. polars/_utils/scan.py +27 -0
  31. polars/_utils/serde.py +63 -0
  32. polars/_utils/slice.py +215 -0
  33. polars/_utils/udfs.py +1251 -0
  34. polars/_utils/unstable.py +63 -0
  35. polars/_utils/various.py +782 -0
  36. polars/_utils/wrap.py +25 -0
  37. polars/api.py +370 -0
  38. polars/catalog/__init__.py +0 -0
  39. polars/catalog/unity/__init__.py +19 -0
  40. polars/catalog/unity/client.py +733 -0
  41. polars/catalog/unity/models.py +152 -0
  42. polars/config.py +1571 -0
  43. polars/convert/__init__.py +25 -0
  44. polars/convert/general.py +1046 -0
  45. polars/convert/normalize.py +261 -0
  46. polars/dataframe/__init__.py +5 -0
  47. polars/dataframe/_html.py +186 -0
  48. polars/dataframe/frame.py +12582 -0
  49. polars/dataframe/group_by.py +1067 -0
  50. polars/dataframe/plotting.py +257 -0
  51. polars/datatype_expr/__init__.py +5 -0
  52. polars/datatype_expr/array.py +56 -0
  53. polars/datatype_expr/datatype_expr.py +304 -0
  54. polars/datatype_expr/list.py +18 -0
  55. polars/datatype_expr/struct.py +69 -0
  56. polars/datatypes/__init__.py +122 -0
  57. polars/datatypes/_parse.py +195 -0
  58. polars/datatypes/_utils.py +48 -0
  59. polars/datatypes/classes.py +1213 -0
  60. polars/datatypes/constants.py +11 -0
  61. polars/datatypes/constructor.py +172 -0
  62. polars/datatypes/convert.py +366 -0
  63. polars/datatypes/group.py +130 -0
  64. polars/exceptions.py +230 -0
  65. polars/expr/__init__.py +7 -0
  66. polars/expr/array.py +964 -0
  67. polars/expr/binary.py +346 -0
  68. polars/expr/categorical.py +306 -0
  69. polars/expr/datetime.py +2620 -0
  70. polars/expr/expr.py +11272 -0
  71. polars/expr/list.py +1408 -0
  72. polars/expr/meta.py +444 -0
  73. polars/expr/name.py +321 -0
  74. polars/expr/string.py +3045 -0
  75. polars/expr/struct.py +357 -0
  76. polars/expr/whenthen.py +185 -0
  77. polars/functions/__init__.py +193 -0
  78. polars/functions/aggregation/__init__.py +33 -0
  79. polars/functions/aggregation/horizontal.py +298 -0
  80. polars/functions/aggregation/vertical.py +341 -0
  81. polars/functions/as_datatype.py +848 -0
  82. polars/functions/business.py +138 -0
  83. polars/functions/col.py +384 -0
  84. polars/functions/datatype.py +121 -0
  85. polars/functions/eager.py +524 -0
  86. polars/functions/escape_regex.py +29 -0
  87. polars/functions/lazy.py +2751 -0
  88. polars/functions/len.py +68 -0
  89. polars/functions/lit.py +210 -0
  90. polars/functions/random.py +22 -0
  91. polars/functions/range/__init__.py +19 -0
  92. polars/functions/range/_utils.py +15 -0
  93. polars/functions/range/date_range.py +303 -0
  94. polars/functions/range/datetime_range.py +370 -0
  95. polars/functions/range/int_range.py +348 -0
  96. polars/functions/range/linear_space.py +311 -0
  97. polars/functions/range/time_range.py +287 -0
  98. polars/functions/repeat.py +301 -0
  99. polars/functions/whenthen.py +353 -0
  100. polars/interchange/__init__.py +10 -0
  101. polars/interchange/buffer.py +77 -0
  102. polars/interchange/column.py +190 -0
  103. polars/interchange/dataframe.py +230 -0
  104. polars/interchange/from_dataframe.py +328 -0
  105. polars/interchange/protocol.py +303 -0
  106. polars/interchange/utils.py +170 -0
  107. polars/io/__init__.py +64 -0
  108. polars/io/_utils.py +317 -0
  109. polars/io/avro.py +49 -0
  110. polars/io/clipboard.py +36 -0
  111. polars/io/cloud/__init__.py +17 -0
  112. polars/io/cloud/_utils.py +80 -0
  113. polars/io/cloud/credential_provider/__init__.py +17 -0
  114. polars/io/cloud/credential_provider/_builder.py +520 -0
  115. polars/io/cloud/credential_provider/_providers.py +618 -0
  116. polars/io/csv/__init__.py +9 -0
  117. polars/io/csv/_utils.py +38 -0
  118. polars/io/csv/batched_reader.py +142 -0
  119. polars/io/csv/functions.py +1495 -0
  120. polars/io/database/__init__.py +6 -0
  121. polars/io/database/_arrow_registry.py +70 -0
  122. polars/io/database/_cursor_proxies.py +147 -0
  123. polars/io/database/_executor.py +578 -0
  124. polars/io/database/_inference.py +314 -0
  125. polars/io/database/_utils.py +144 -0
  126. polars/io/database/functions.py +516 -0
  127. polars/io/delta.py +499 -0
  128. polars/io/iceberg/__init__.py +3 -0
  129. polars/io/iceberg/_utils.py +697 -0
  130. polars/io/iceberg/dataset.py +556 -0
  131. polars/io/iceberg/functions.py +151 -0
  132. polars/io/ipc/__init__.py +8 -0
  133. polars/io/ipc/functions.py +514 -0
  134. polars/io/json/__init__.py +3 -0
  135. polars/io/json/read.py +101 -0
  136. polars/io/ndjson.py +332 -0
  137. polars/io/parquet/__init__.py +17 -0
  138. polars/io/parquet/field_overwrites.py +140 -0
  139. polars/io/parquet/functions.py +722 -0
  140. polars/io/partition.py +491 -0
  141. polars/io/plugins.py +187 -0
  142. polars/io/pyarrow_dataset/__init__.py +5 -0
  143. polars/io/pyarrow_dataset/anonymous_scan.py +109 -0
  144. polars/io/pyarrow_dataset/functions.py +79 -0
  145. polars/io/scan_options/__init__.py +5 -0
  146. polars/io/scan_options/_options.py +59 -0
  147. polars/io/scan_options/cast_options.py +126 -0
  148. polars/io/spreadsheet/__init__.py +6 -0
  149. polars/io/spreadsheet/_utils.py +52 -0
  150. polars/io/spreadsheet/_write_utils.py +647 -0
  151. polars/io/spreadsheet/functions.py +1323 -0
  152. polars/lazyframe/__init__.py +9 -0
  153. polars/lazyframe/engine_config.py +61 -0
  154. polars/lazyframe/frame.py +8564 -0
  155. polars/lazyframe/group_by.py +669 -0
  156. polars/lazyframe/in_process.py +42 -0
  157. polars/lazyframe/opt_flags.py +333 -0
  158. polars/meta/__init__.py +14 -0
  159. polars/meta/build.py +33 -0
  160. polars/meta/index_type.py +27 -0
  161. polars/meta/thread_pool.py +50 -0
  162. polars/meta/versions.py +120 -0
  163. polars/ml/__init__.py +0 -0
  164. polars/ml/torch.py +213 -0
  165. polars/ml/utilities.py +30 -0
  166. polars/plugins.py +155 -0
  167. polars/py.typed +0 -0
  168. polars/pyproject.toml +96 -0
  169. polars/schema.py +265 -0
  170. polars/selectors.py +3117 -0
  171. polars/series/__init__.py +5 -0
  172. polars/series/array.py +776 -0
  173. polars/series/binary.py +254 -0
  174. polars/series/categorical.py +246 -0
  175. polars/series/datetime.py +2275 -0
  176. polars/series/list.py +1087 -0
  177. polars/series/plotting.py +191 -0
  178. polars/series/series.py +9197 -0
  179. polars/series/string.py +2367 -0
  180. polars/series/struct.py +154 -0
  181. polars/series/utils.py +191 -0
  182. polars/sql/__init__.py +7 -0
  183. polars/sql/context.py +677 -0
  184. polars/sql/functions.py +139 -0
  185. polars/string_cache.py +185 -0
  186. polars/testing/__init__.py +13 -0
  187. polars/testing/asserts/__init__.py +9 -0
  188. polars/testing/asserts/frame.py +231 -0
  189. polars/testing/asserts/series.py +219 -0
  190. polars/testing/asserts/utils.py +12 -0
  191. polars/testing/parametric/__init__.py +33 -0
  192. polars/testing/parametric/profiles.py +107 -0
  193. polars/testing/parametric/strategies/__init__.py +22 -0
  194. polars/testing/parametric/strategies/_utils.py +14 -0
  195. polars/testing/parametric/strategies/core.py +615 -0
  196. polars/testing/parametric/strategies/data.py +452 -0
  197. polars/testing/parametric/strategies/dtype.py +436 -0
  198. polars/testing/parametric/strategies/legacy.py +169 -0
  199. polars/type_aliases.py +24 -0
  200. polars_runtime_compat-1.34.0b2.dist-info/METADATA +190 -0
  201. polars_runtime_compat-1.34.0b2.dist-info/RECORD +203 -0
  202. polars_runtime_compat-1.34.0b2.dist-info/WHEEL +4 -0
  203. polars_runtime_compat-1.34.0b2.dist-info/licenses/LICENSE +20 -0
polars/_reexport.py ADDED
@@ -0,0 +1,23 @@
1
+ """Re-export Polars functionality to avoid cyclical imports."""
2
+
3
+ from polars.dataframe import DataFrame
4
+ from polars.datatype_expr import DataTypeExpr
5
+ from polars.datatypes import DataType, DataTypeClass
6
+ from polars.expr import Expr, When
7
+ from polars.lazyframe import LazyFrame
8
+ from polars.schema import Schema
9
+ from polars.selectors import Selector
10
+ from polars.series import Series
11
+
12
+ __all__ = [
13
+ "DataFrame",
14
+ "DataTypeExpr",
15
+ "DataType",
16
+ "DataTypeClass",
17
+ "Expr",
18
+ "LazyFrame",
19
+ "Schema",
20
+ "Selector",
21
+ "Series",
22
+ "When",
23
+ ]
polars/_typing.py ADDED
@@ -0,0 +1,478 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Collection, Iterable, Mapping, Sequence
4
+ from pathlib import Path
5
+ from typing import (
6
+ IO,
7
+ TYPE_CHECKING,
8
+ Any,
9
+ Callable,
10
+ Literal,
11
+ Protocol,
12
+ TypedDict,
13
+ TypeVar,
14
+ Union,
15
+ )
16
+
17
+ if TYPE_CHECKING:
18
+ import contextlib
19
+ import sys
20
+ from datetime import date, datetime, time, timedelta
21
+ from decimal import Decimal
22
+
23
+ from sqlalchemy.engine import Connection, Engine
24
+ from sqlalchemy.orm import Session
25
+
26
+ from polars import DataFrame, Expr, LazyFrame, Series
27
+ from polars._dependencies import numpy as np
28
+ from polars._dependencies import pandas as pd
29
+ from polars._dependencies import pyarrow as pa
30
+ from polars._dependencies import torch
31
+ from polars.datatypes import DataType, DataTypeClass, IntegerType, TemporalType
32
+ from polars.lazyframe.engine_config import GPUEngine
33
+ from polars.selectors import Selector
34
+
35
+ with contextlib.suppress(ImportError): # Module not available when building docs
36
+ from polars._plr import PyPartitioning
37
+
38
+ if sys.version_info >= (3, 10):
39
+ from typing import TypeAlias
40
+ else:
41
+ from typing_extensions import TypeAlias
42
+
43
+
44
+ class ArrowArrayExportable(Protocol):
45
+ """Type protocol for Arrow C Data Interface via Arrow PyCapsule Interface."""
46
+
47
+ def __arrow_c_array__(
48
+ self, requested_schema: object | None = None
49
+ ) -> tuple[object, object]: ...
50
+
51
+
52
+ class ArrowStreamExportable(Protocol):
53
+ """Type protocol for Arrow C Stream Interface via Arrow PyCapsule Interface."""
54
+
55
+ def __arrow_c_stream__(self, requested_schema: object | None = None) -> object: ...
56
+
57
+
58
+ class ArrowSchemaExportable(Protocol):
59
+ """Type protocol for Arrow C Schema Interface via Arrow PyCapsule Interface."""
60
+
61
+ def __arrow_c_schema__(self) -> object: ...
62
+
63
+
64
+ # Data types
65
+ PolarsDataType: TypeAlias = Union["DataTypeClass", "DataType"]
66
+ PolarsTemporalType: TypeAlias = Union[type["TemporalType"], "TemporalType"]
67
+ PolarsIntegerType: TypeAlias = Union[type["IntegerType"], "IntegerType"]
68
+ OneOrMoreDataTypes: TypeAlias = Union[PolarsDataType, Iterable[PolarsDataType]]
69
+ PythonDataType: TypeAlias = Union[
70
+ type[int],
71
+ type[float],
72
+ type[bool],
73
+ type[str],
74
+ type["date"],
75
+ type["time"],
76
+ type["datetime"],
77
+ type["timedelta"],
78
+ type[list[Any]],
79
+ type[tuple[Any, ...]],
80
+ type[bytes],
81
+ type[object],
82
+ type["Decimal"],
83
+ type[None],
84
+ ]
85
+
86
+ SchemaDefinition: TypeAlias = Union[
87
+ Mapping[str, Union[PolarsDataType, PythonDataType, None]],
88
+ Sequence[Union[str, tuple[str, Union[PolarsDataType, PythonDataType, None]]]],
89
+ ]
90
+ SchemaDict: TypeAlias = Mapping[str, PolarsDataType]
91
+
92
+ NumericLiteral: TypeAlias = Union[int, float, "Decimal"]
93
+ TemporalLiteral: TypeAlias = Union["date", "time", "datetime", "timedelta"]
94
+ NonNestedLiteral: TypeAlias = Union[NumericLiteral, TemporalLiteral, str, bool, bytes]
95
+ # Python literal types (can convert into a `lit` expression)
96
+ PythonLiteral: TypeAlias = Union[NonNestedLiteral, "np.ndarray[Any, Any]", list[Any]]
97
+ # Inputs that can convert into a `col` expression
98
+ IntoExprColumn: TypeAlias = Union["Expr", "Series", str]
99
+ # Inputs that can convert into an expression
100
+ IntoExpr: TypeAlias = Union[PythonLiteral, IntoExprColumn, None]
101
+
102
+ ComparisonOperator: TypeAlias = Literal["eq", "neq", "gt", "lt", "gt_eq", "lt_eq"]
103
+
104
+ # selector type, and related collection/sequence
105
+ SelectorType: TypeAlias = "Selector"
106
+ ColumnNameOrSelector: TypeAlias = Union[str, SelectorType]
107
+
108
+ # User-facing string literal types
109
+ # The following all have an equivalent Rust enum with the same name
110
+ Ambiguous: TypeAlias = Literal["earliest", "latest", "raise", "null"]
111
+ AvroCompression: TypeAlias = Literal["uncompressed", "snappy", "deflate"]
112
+ CsvQuoteStyle: TypeAlias = Literal["necessary", "always", "non_numeric", "never"]
113
+ CategoricalOrdering: TypeAlias = Literal["physical", "lexical"]
114
+ CsvEncoding: TypeAlias = Literal["utf8", "utf8-lossy"]
115
+ ColumnMapping: TypeAlias = tuple[Literal["iceberg-column-mapping"], "pa.Schema"]
116
+ DefaultFieldValues: TypeAlias = tuple[
117
+ Literal["iceberg"], dict[int, Union["Series", str]]
118
+ ]
119
+ DeletionFiles: TypeAlias = tuple[
120
+ Literal["iceberg-position-delete"], dict[int, list[str]]
121
+ ]
122
+ FillNullStrategy: TypeAlias = Literal[
123
+ "forward", "backward", "min", "max", "mean", "zero", "one"
124
+ ]
125
+ FloatFmt: TypeAlias = Literal["full", "mixed"]
126
+ IndexOrder: TypeAlias = Literal["c", "fortran"]
127
+ IpcCompression: TypeAlias = Literal["uncompressed", "lz4", "zstd"]
128
+ JoinValidation: TypeAlias = Literal["m:m", "m:1", "1:m", "1:1"]
129
+ Label: TypeAlias = Literal["left", "right", "datapoint"]
130
+ MaintainOrderJoin: TypeAlias = Literal[
131
+ "none", "left", "right", "left_right", "right_left"
132
+ ]
133
+ NonExistent: TypeAlias = Literal["raise", "null"]
134
+ NullBehavior: TypeAlias = Literal["ignore", "drop"]
135
+ ParallelStrategy: TypeAlias = Literal[
136
+ "auto", "columns", "row_groups", "prefiltered", "none"
137
+ ]
138
+ ParquetCompression: TypeAlias = Literal[
139
+ "lz4", "uncompressed", "snappy", "gzip", "lzo", "brotli", "zstd"
140
+ ]
141
+ PivotAgg: TypeAlias = Literal[
142
+ "min", "max", "first", "last", "sum", "mean", "median", "len"
143
+ ]
144
+ QuantileMethod: TypeAlias = Literal[
145
+ "nearest", "higher", "lower", "midpoint", "linear", "equiprobable"
146
+ ]
147
+ RankMethod: TypeAlias = Literal["average", "min", "max", "dense", "ordinal", "random"]
148
+ Roll: TypeAlias = Literal["raise", "forward", "backward"]
149
+ RoundMode: TypeAlias = Literal["half_to_even", "half_away_from_zero"]
150
+ SerializationFormat: TypeAlias = Literal["binary", "json"]
151
+ Endianness: TypeAlias = Literal["little", "big"]
152
+ SizeUnit: TypeAlias = Literal[
153
+ "b",
154
+ "kb",
155
+ "mb",
156
+ "gb",
157
+ "tb",
158
+ "bytes",
159
+ "kilobytes",
160
+ "megabytes",
161
+ "gigabytes",
162
+ "terabytes",
163
+ ]
164
+ StartBy: TypeAlias = Literal[
165
+ "window",
166
+ "datapoint",
167
+ "monday",
168
+ "tuesday",
169
+ "wednesday",
170
+ "thursday",
171
+ "friday",
172
+ "saturday",
173
+ "sunday",
174
+ ]
175
+ SyncOnCloseMethod: TypeAlias = Literal["data", "all"]
176
+ TimeUnit: TypeAlias = Literal["ns", "us", "ms"]
177
+ UnicodeForm: TypeAlias = Literal["NFC", "NFKC", "NFD", "NFKD"]
178
+ UniqueKeepStrategy: TypeAlias = Literal["first", "last", "any", "none"]
179
+ UnstackDirection: TypeAlias = Literal["vertical", "horizontal"]
180
+ MapElementsStrategy: TypeAlias = Literal["thread_local", "threading"]
181
+
182
+ # The following have a Rust enum equivalent with a different name
183
+ AsofJoinStrategy: TypeAlias = Literal["backward", "forward", "nearest"] # AsofStrategy
184
+ ClosedInterval: TypeAlias = Literal["left", "right", "both", "none"] # ClosedWindow
185
+ InterpolationMethod: TypeAlias = Literal["linear", "nearest"]
186
+ JoinStrategy: TypeAlias = Literal[
187
+ "inner", "left", "right", "full", "semi", "anti", "cross", "outer"
188
+ ] # JoinType
189
+ ListToStructWidthStrategy: TypeAlias = Literal["first_non_null", "max_width"]
190
+
191
+ # The following have no equivalent on the Rust side
192
+ ConcatMethod = Literal[
193
+ "vertical",
194
+ "vertical_relaxed",
195
+ "diagonal",
196
+ "diagonal_relaxed",
197
+ "horizontal",
198
+ "align",
199
+ "align_full",
200
+ "align_inner",
201
+ "align_left",
202
+ "align_right",
203
+ ]
204
+ CorrelationMethod: TypeAlias = Literal["pearson", "spearman"]
205
+ DbReadEngine: TypeAlias = Literal["adbc", "connectorx"]
206
+ DbWriteEngine: TypeAlias = Literal["sqlalchemy", "adbc"]
207
+ DbWriteMode: TypeAlias = Literal["replace", "append", "fail"]
208
+ EpochTimeUnit = Literal["ns", "us", "ms", "s", "d"]
209
+ JaxExportType: TypeAlias = Literal["array", "dict"]
210
+ Orientation: TypeAlias = Literal["col", "row"]
211
+ SearchSortedSide: TypeAlias = Literal["any", "left", "right"]
212
+ TorchExportType: TypeAlias = Literal["tensor", "dataset", "dict"]
213
+ TransferEncoding: TypeAlias = Literal["hex", "base64"]
214
+ WindowMappingStrategy: TypeAlias = Literal["group_to_rows", "join", "explode"]
215
+ ExplainFormat: TypeAlias = Literal["plain", "tree"]
216
+
217
+ # type signature for allowed frame init
218
+ FrameInitTypes: TypeAlias = Union[
219
+ Mapping[str, Union[Sequence[object], Mapping[str, Sequence[object]], "Series"]],
220
+ Sequence[Any],
221
+ "np.ndarray[Any, Any]",
222
+ "pa.Table",
223
+ "pd.DataFrame",
224
+ "ArrowArrayExportable",
225
+ "ArrowStreamExportable",
226
+ "torch.Tensor",
227
+ ]
228
+
229
+ # Excel IO
230
+ ColumnFormatDict: TypeAlias = Mapping[
231
+ # dict of colname(s) or selector(s) to format string or dict
232
+ Union[ColumnNameOrSelector, tuple[ColumnNameOrSelector, ...]],
233
+ Union[str, Mapping[str, str]],
234
+ ]
235
+ ConditionalFormatDict: TypeAlias = Mapping[
236
+ # dict of colname(s) to str, dict, or sequence of str/dict
237
+ Union[ColumnNameOrSelector, Collection[str]],
238
+ Union[str, Union[Mapping[str, Any], Sequence[Union[str, Mapping[str, Any]]]]],
239
+ ]
240
+ ColumnTotalsDefinition: TypeAlias = Union[
241
+ # dict of colname(s) to str, a collection of str, or a boolean
242
+ Mapping[Union[ColumnNameOrSelector, tuple[ColumnNameOrSelector]], str],
243
+ Sequence[str],
244
+ bool,
245
+ ]
246
+ ColumnWidthsDefinition: TypeAlias = Union[
247
+ Mapping[ColumnNameOrSelector, Union[tuple[str, ...], int]], int
248
+ ]
249
+ RowTotalsDefinition: TypeAlias = Union[
250
+ # dict of colname to str(s), a collection of str, or a boolean
251
+ Mapping[str, Union[str, Collection[str]]],
252
+ Collection[str],
253
+ bool,
254
+ ]
255
+
256
+ # standard/named hypothesis profiles used for parametric testing
257
+ ParametricProfileNames: TypeAlias = Literal["fast", "balanced", "expensive"]
258
+
259
+ # typevars for core polars types
260
+ PolarsType = TypeVar("PolarsType", "DataFrame", "LazyFrame", "Series", "Expr")
261
+ FrameType = TypeVar("FrameType", "DataFrame", "LazyFrame")
262
+ BufferInfo: TypeAlias = tuple[int, int, int]
263
+
264
+ # type alias for supported spreadsheet engines
265
+ ExcelSpreadsheetEngine: TypeAlias = Literal["calamine", "openpyxl", "xlsx2csv"]
266
+
267
+
268
+ class SeriesBuffers(TypedDict):
269
+ """Underlying buffers of a Series."""
270
+
271
+ values: Series
272
+ validity: Series | None
273
+ offsets: Series | None
274
+
275
+
276
+ # minimal protocol definitions that can reasonably represent
277
+ # an executable connection, cursor, or equivalent object
278
+ class BasicConnection(Protocol):
279
+ def cursor(self, *args: Any, **kwargs: Any) -> Any:
280
+ """Return a cursor object."""
281
+
282
+
283
+ class BasicCursor(Protocol):
284
+ def execute(self, *args: Any, **kwargs: Any) -> Any:
285
+ """Execute a query."""
286
+
287
+
288
+ class Cursor(BasicCursor):
289
+ def fetchall(self, *args: Any, **kwargs: Any) -> Any:
290
+ """Fetch all results."""
291
+
292
+ def fetchmany(self, *args: Any, **kwargs: Any) -> Any:
293
+ """Fetch results in batches."""
294
+
295
+
296
+ AlchemyConnection: TypeAlias = Union["Connection", "Engine", "Session"]
297
+ ConnectionOrCursor: TypeAlias = Union[
298
+ BasicConnection, BasicCursor, Cursor, AlchemyConnection
299
+ ]
300
+
301
+ # Annotations for `__getitem__` methods
302
+ SingleIndexSelector: TypeAlias = int
303
+ MultiIndexSelector: TypeAlias = Union[
304
+ slice,
305
+ range,
306
+ Sequence[int],
307
+ "Series",
308
+ "np.ndarray[Any, Any]",
309
+ ]
310
+ SingleNameSelector: TypeAlias = str
311
+ MultiNameSelector: TypeAlias = Union[
312
+ slice,
313
+ Sequence[str],
314
+ "Series",
315
+ "np.ndarray[Any, Any]",
316
+ ]
317
+ BooleanMask: TypeAlias = Union[
318
+ Sequence[bool],
319
+ "Series",
320
+ "np.ndarray[Any, Any]",
321
+ ]
322
+ SingleColSelector: TypeAlias = Union[SingleIndexSelector, SingleNameSelector]
323
+ MultiColSelector: TypeAlias = Union[MultiIndexSelector, MultiNameSelector, BooleanMask]
324
+
325
+ # LazyFrame engine selection
326
+ EngineType: TypeAlias = Union[
327
+ Literal["auto", "in-memory", "streaming", "gpu"], "GPUEngine"
328
+ ]
329
+
330
+ PlanStage: TypeAlias = Literal["ir", "physical"]
331
+
332
+ FileSource: TypeAlias = Union[
333
+ str,
334
+ Path,
335
+ IO[bytes],
336
+ bytes,
337
+ list[str],
338
+ list[Path],
339
+ list[IO[bytes]],
340
+ list[bytes],
341
+ ]
342
+
343
+ JSONEncoder = Union[Callable[[Any], bytes], Callable[[Any], str]]
344
+
345
+ DeprecationType: TypeAlias = Literal[
346
+ "function",
347
+ "renamed_parameter",
348
+ "streaming_parameter",
349
+ "nonkeyword_arguments",
350
+ "parameter_as_multi_positional",
351
+ ]
352
+
353
+
354
+ class PartitioningScheme:
355
+ def __init__(
356
+ self,
357
+ py_partitioning: PyPartitioning,
358
+ ) -> None:
359
+ self._py_partitioning = py_partitioning
360
+
361
+ @property
362
+ def _base_path(self) -> str | None:
363
+ return self._py_partitioning.base_path
364
+
365
+
366
+ __all__ = [
367
+ "Ambiguous",
368
+ "ArrowArrayExportable",
369
+ "ArrowStreamExportable",
370
+ "AsofJoinStrategy",
371
+ "AvroCompression",
372
+ "BooleanMask",
373
+ "BufferInfo",
374
+ "CategoricalOrdering",
375
+ "ClosedInterval",
376
+ "ColumnFormatDict",
377
+ "ColumnNameOrSelector",
378
+ "ColumnTotalsDefinition",
379
+ "ColumnWidthsDefinition",
380
+ "ComparisonOperator",
381
+ "ConcatMethod",
382
+ "ConditionalFormatDict",
383
+ "ConnectionOrCursor",
384
+ "CorrelationMethod",
385
+ "CsvEncoding",
386
+ "CsvQuoteStyle",
387
+ "Cursor",
388
+ "DbReadEngine",
389
+ "DbWriteEngine",
390
+ "DbWriteMode",
391
+ "DeprecationType",
392
+ "Endianness",
393
+ "EngineType",
394
+ "EpochTimeUnit",
395
+ "ExcelSpreadsheetEngine",
396
+ "ExplainFormat",
397
+ "FileSource",
398
+ "FillNullStrategy",
399
+ "FloatFmt",
400
+ "FrameInitTypes",
401
+ "FrameType",
402
+ "IndexOrder",
403
+ "InterpolationMethod",
404
+ "IntoExpr",
405
+ "IntoExprColumn",
406
+ "IpcCompression",
407
+ "JSONEncoder",
408
+ "JaxExportType",
409
+ "JoinStrategy",
410
+ "JoinValidation",
411
+ "Label",
412
+ "ListToStructWidthStrategy",
413
+ "MaintainOrderJoin",
414
+ "MapElementsStrategy",
415
+ "MultiColSelector",
416
+ "MultiIndexSelector",
417
+ "MultiNameSelector",
418
+ "NonExistent",
419
+ "NonNestedLiteral",
420
+ "NullBehavior",
421
+ "NumericLiteral",
422
+ "OneOrMoreDataTypes",
423
+ "Orientation",
424
+ "ParallelStrategy",
425
+ "ParametricProfileNames",
426
+ "ParquetCompression",
427
+ "PartitioningScheme",
428
+ "PivotAgg",
429
+ "PolarsDataType",
430
+ "PolarsIntegerType",
431
+ "PolarsTemporalType",
432
+ "PolarsType",
433
+ "PythonDataType",
434
+ "PythonLiteral",
435
+ "QuantileMethod",
436
+ "RankMethod",
437
+ "Roll",
438
+ "RowTotalsDefinition",
439
+ "SchemaDefinition",
440
+ "SchemaDict",
441
+ "SearchSortedSide",
442
+ "SelectorType",
443
+ "SerializationFormat",
444
+ "SeriesBuffers",
445
+ "SingleColSelector",
446
+ "SingleIndexSelector",
447
+ "SingleNameSelector",
448
+ "SizeUnit",
449
+ "StartBy",
450
+ "SyncOnCloseMethod",
451
+ "TemporalLiteral",
452
+ "TimeUnit",
453
+ "TorchExportType",
454
+ "TransferEncoding",
455
+ "UnicodeForm",
456
+ "UniqueKeepStrategy",
457
+ "UnstackDirection",
458
+ "WindowMappingStrategy",
459
+ ]
460
+
461
+
462
+ class ParquetMetadataContext:
463
+ """
464
+ The context given when writing file-level parquet metadata.
465
+
466
+ .. warning::
467
+ This functionality is considered **experimental**. It may be removed or
468
+ changed at any point without it being considered a breaking change.
469
+ """
470
+
471
+ def __init__(self, *, arrow_schema: str) -> None:
472
+ self.arrow_schema = arrow_schema
473
+
474
+ arrow_schema: str #: The base64 encoded arrow schema that is going to be written into metadata.
475
+
476
+
477
+ ParquetMetadataFn: TypeAlias = Callable[[ParquetMetadataContext], dict[str, str]]
478
+ ParquetMetadata: TypeAlias = Union[dict[str, str], ParquetMetadataFn]
@@ -0,0 +1,37 @@
1
+ """
2
+ Utility functions.
3
+
4
+ Functions that are part of the public API are re-exported here.
5
+ """
6
+
7
+ from polars._utils.convert import (
8
+ date_to_int,
9
+ datetime_to_int,
10
+ time_to_int,
11
+ timedelta_to_int,
12
+ to_py_date,
13
+ to_py_datetime,
14
+ to_py_decimal,
15
+ to_py_time,
16
+ to_py_timedelta,
17
+ )
18
+ from polars._utils.scan import _execute_from_rust
19
+ from polars._utils.various import NoDefault, _polars_warn, is_column, no_default
20
+
21
+ __all__ = [
22
+ "NoDefault",
23
+ "is_column",
24
+ "no_default",
25
+ # Required for Rust bindings
26
+ "date_to_int",
27
+ "datetime_to_int",
28
+ "time_to_int",
29
+ "timedelta_to_int",
30
+ "_execute_from_rust",
31
+ "_polars_warn",
32
+ "to_py_date",
33
+ "to_py_datetime",
34
+ "to_py_decimal",
35
+ "to_py_time",
36
+ "to_py_timedelta",
37
+ ]
@@ -0,0 +1,102 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Awaitable
4
+ from typing import TYPE_CHECKING, Any, Generic, TypeVar
5
+
6
+ from polars._dependencies import _GEVENT_AVAILABLE
7
+ from polars._utils.wrap import wrap_df
8
+
9
+ if TYPE_CHECKING:
10
+ from asyncio.futures import Future
11
+ from collections.abc import Generator
12
+
13
+ from polars._plr import PyDataFrame
14
+
15
+
16
+ T = TypeVar("T")
17
+
18
+
19
+ class _GeventDataFrameResult(Generic[T]):
20
+ __slots__ = ("_result", "_value", "_watcher")
21
+
22
+ def __init__(self) -> None:
23
+ if not _GEVENT_AVAILABLE:
24
+ msg = (
25
+ "gevent is required for using LazyFrame.collect_async(gevent=True) or"
26
+ "polars.collect_all_async(gevent=True)"
27
+ )
28
+ raise ImportError(msg)
29
+
30
+ from gevent.event import AsyncResult # type: ignore[import-untyped]
31
+ from gevent.hub import get_hub # type: ignore[import-untyped]
32
+
33
+ self._value: None | Exception | PyDataFrame | list[PyDataFrame] = None
34
+ self._result = AsyncResult()
35
+
36
+ self._watcher = get_hub().loop.async_()
37
+ self._watcher.start(self._watcher_callback)
38
+
39
+ def get(
40
+ self,
41
+ block: bool = True, # noqa: FBT001
42
+ timeout: float | int | None = None,
43
+ ) -> T:
44
+ return self.result.get(block=block, timeout=timeout)
45
+
46
+ @property
47
+ def result(self) -> Any:
48
+ # required if we did not made any switches and just want results later
49
+ # with block=False and possibly without timeout
50
+ if self._value is not None and not self._result.ready():
51
+ self._watcher_callback()
52
+ return self._result
53
+
54
+ def _watcher_callback(self) -> None:
55
+ if isinstance(self._value, Exception):
56
+ self._result.set_exception(self._value)
57
+ else:
58
+ self._result.set(self._value)
59
+ self._watcher.close()
60
+
61
+ def _callback(self, obj: PyDataFrame | Exception) -> None:
62
+ if not isinstance(obj, Exception):
63
+ obj = wrap_df(obj) # type: ignore[assignment]
64
+ self._value = obj
65
+ self._watcher.send()
66
+
67
+ def _callback_all(self, obj: list[PyDataFrame] | Exception) -> None:
68
+ if not isinstance(obj, Exception):
69
+ obj = [wrap_df(pydf) for pydf in obj] # type: ignore[misc]
70
+ self._value = obj
71
+ self._watcher.send()
72
+
73
+
74
+ class _AioDataFrameResult(Awaitable[T], Generic[T]):
75
+ __slots__ = ("loop", "result")
76
+
77
+ def __init__(self) -> None:
78
+ from asyncio import get_event_loop
79
+
80
+ self.loop = get_event_loop()
81
+ self.result: Future[T] = self.loop.create_future()
82
+
83
+ def __await__(self) -> Generator[Any, None, T]:
84
+ return self.result.__await__()
85
+
86
+ def _callback(self, obj: PyDataFrame | Exception) -> None:
87
+ if isinstance(obj, Exception):
88
+ self.loop.call_soon_threadsafe(self.result.set_exception, obj)
89
+ else:
90
+ self.loop.call_soon_threadsafe(
91
+ self.result.set_result, # type: ignore[arg-type]
92
+ wrap_df(obj),
93
+ )
94
+
95
+ def _callback_all(self, obj: list[PyDataFrame] | Exception) -> None:
96
+ if isinstance(obj, Exception):
97
+ self.loop.call_soon_threadsafe(self.result.set_exception, obj)
98
+ else:
99
+ self.loop.call_soon_threadsafe(
100
+ self.result.set_result, # type: ignore[arg-type]
101
+ [wrap_df(pydf) for pydf in obj],
102
+ )