polars-runtime-compat 1.34.0b2__cp39-abi3-win_amd64.whl → 1.34.0b4__cp39-abi3-win_amd64.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.
- _polars_runtime_compat/_polars_runtime_compat.pyd +0 -0
- {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/METADATA +1 -1
- polars_runtime_compat-1.34.0b4.dist-info/RECORD +6 -0
- polars/__init__.py +0 -528
- polars/_cpu_check.py +0 -265
- polars/_dependencies.py +0 -355
- polars/_plr.py +0 -99
- polars/_plr.pyi +0 -2496
- polars/_reexport.py +0 -23
- polars/_typing.py +0 -478
- polars/_utils/__init__.py +0 -37
- polars/_utils/async_.py +0 -102
- polars/_utils/cache.py +0 -176
- polars/_utils/cloud.py +0 -40
- polars/_utils/constants.py +0 -29
- polars/_utils/construction/__init__.py +0 -46
- polars/_utils/construction/dataframe.py +0 -1397
- polars/_utils/construction/other.py +0 -72
- polars/_utils/construction/series.py +0 -560
- polars/_utils/construction/utils.py +0 -118
- polars/_utils/convert.py +0 -224
- polars/_utils/deprecation.py +0 -406
- polars/_utils/getitem.py +0 -457
- polars/_utils/logging.py +0 -11
- polars/_utils/nest_asyncio.py +0 -264
- polars/_utils/parquet.py +0 -15
- polars/_utils/parse/__init__.py +0 -12
- polars/_utils/parse/expr.py +0 -242
- polars/_utils/polars_version.py +0 -19
- polars/_utils/pycapsule.py +0 -53
- polars/_utils/scan.py +0 -27
- polars/_utils/serde.py +0 -63
- polars/_utils/slice.py +0 -215
- polars/_utils/udfs.py +0 -1251
- polars/_utils/unstable.py +0 -63
- polars/_utils/various.py +0 -782
- polars/_utils/wrap.py +0 -25
- polars/api.py +0 -370
- polars/catalog/__init__.py +0 -0
- polars/catalog/unity/__init__.py +0 -19
- polars/catalog/unity/client.py +0 -733
- polars/catalog/unity/models.py +0 -152
- polars/config.py +0 -1571
- polars/convert/__init__.py +0 -25
- polars/convert/general.py +0 -1046
- polars/convert/normalize.py +0 -261
- polars/dataframe/__init__.py +0 -5
- polars/dataframe/_html.py +0 -186
- polars/dataframe/frame.py +0 -12582
- polars/dataframe/group_by.py +0 -1067
- polars/dataframe/plotting.py +0 -257
- polars/datatype_expr/__init__.py +0 -5
- polars/datatype_expr/array.py +0 -56
- polars/datatype_expr/datatype_expr.py +0 -304
- polars/datatype_expr/list.py +0 -18
- polars/datatype_expr/struct.py +0 -69
- polars/datatypes/__init__.py +0 -122
- polars/datatypes/_parse.py +0 -195
- polars/datatypes/_utils.py +0 -48
- polars/datatypes/classes.py +0 -1213
- polars/datatypes/constants.py +0 -11
- polars/datatypes/constructor.py +0 -172
- polars/datatypes/convert.py +0 -366
- polars/datatypes/group.py +0 -130
- polars/exceptions.py +0 -230
- polars/expr/__init__.py +0 -7
- polars/expr/array.py +0 -964
- polars/expr/binary.py +0 -346
- polars/expr/categorical.py +0 -306
- polars/expr/datetime.py +0 -2620
- polars/expr/expr.py +0 -11272
- polars/expr/list.py +0 -1408
- polars/expr/meta.py +0 -444
- polars/expr/name.py +0 -321
- polars/expr/string.py +0 -3045
- polars/expr/struct.py +0 -357
- polars/expr/whenthen.py +0 -185
- polars/functions/__init__.py +0 -193
- polars/functions/aggregation/__init__.py +0 -33
- polars/functions/aggregation/horizontal.py +0 -298
- polars/functions/aggregation/vertical.py +0 -341
- polars/functions/as_datatype.py +0 -848
- polars/functions/business.py +0 -138
- polars/functions/col.py +0 -384
- polars/functions/datatype.py +0 -121
- polars/functions/eager.py +0 -524
- polars/functions/escape_regex.py +0 -29
- polars/functions/lazy.py +0 -2751
- polars/functions/len.py +0 -68
- polars/functions/lit.py +0 -210
- polars/functions/random.py +0 -22
- polars/functions/range/__init__.py +0 -19
- polars/functions/range/_utils.py +0 -15
- polars/functions/range/date_range.py +0 -303
- polars/functions/range/datetime_range.py +0 -370
- polars/functions/range/int_range.py +0 -348
- polars/functions/range/linear_space.py +0 -311
- polars/functions/range/time_range.py +0 -287
- polars/functions/repeat.py +0 -301
- polars/functions/whenthen.py +0 -353
- polars/interchange/__init__.py +0 -10
- polars/interchange/buffer.py +0 -77
- polars/interchange/column.py +0 -190
- polars/interchange/dataframe.py +0 -230
- polars/interchange/from_dataframe.py +0 -328
- polars/interchange/protocol.py +0 -303
- polars/interchange/utils.py +0 -170
- polars/io/__init__.py +0 -64
- polars/io/_utils.py +0 -317
- polars/io/avro.py +0 -49
- polars/io/clipboard.py +0 -36
- polars/io/cloud/__init__.py +0 -17
- polars/io/cloud/_utils.py +0 -80
- polars/io/cloud/credential_provider/__init__.py +0 -17
- polars/io/cloud/credential_provider/_builder.py +0 -520
- polars/io/cloud/credential_provider/_providers.py +0 -618
- polars/io/csv/__init__.py +0 -9
- polars/io/csv/_utils.py +0 -38
- polars/io/csv/batched_reader.py +0 -142
- polars/io/csv/functions.py +0 -1495
- polars/io/database/__init__.py +0 -6
- polars/io/database/_arrow_registry.py +0 -70
- polars/io/database/_cursor_proxies.py +0 -147
- polars/io/database/_executor.py +0 -578
- polars/io/database/_inference.py +0 -314
- polars/io/database/_utils.py +0 -144
- polars/io/database/functions.py +0 -516
- polars/io/delta.py +0 -499
- polars/io/iceberg/__init__.py +0 -3
- polars/io/iceberg/_utils.py +0 -697
- polars/io/iceberg/dataset.py +0 -556
- polars/io/iceberg/functions.py +0 -151
- polars/io/ipc/__init__.py +0 -8
- polars/io/ipc/functions.py +0 -514
- polars/io/json/__init__.py +0 -3
- polars/io/json/read.py +0 -101
- polars/io/ndjson.py +0 -332
- polars/io/parquet/__init__.py +0 -17
- polars/io/parquet/field_overwrites.py +0 -140
- polars/io/parquet/functions.py +0 -722
- polars/io/partition.py +0 -491
- polars/io/plugins.py +0 -187
- polars/io/pyarrow_dataset/__init__.py +0 -5
- polars/io/pyarrow_dataset/anonymous_scan.py +0 -109
- polars/io/pyarrow_dataset/functions.py +0 -79
- polars/io/scan_options/__init__.py +0 -5
- polars/io/scan_options/_options.py +0 -59
- polars/io/scan_options/cast_options.py +0 -126
- polars/io/spreadsheet/__init__.py +0 -6
- polars/io/spreadsheet/_utils.py +0 -52
- polars/io/spreadsheet/_write_utils.py +0 -647
- polars/io/spreadsheet/functions.py +0 -1323
- polars/lazyframe/__init__.py +0 -9
- polars/lazyframe/engine_config.py +0 -61
- polars/lazyframe/frame.py +0 -8564
- polars/lazyframe/group_by.py +0 -669
- polars/lazyframe/in_process.py +0 -42
- polars/lazyframe/opt_flags.py +0 -333
- polars/meta/__init__.py +0 -14
- polars/meta/build.py +0 -33
- polars/meta/index_type.py +0 -27
- polars/meta/thread_pool.py +0 -50
- polars/meta/versions.py +0 -120
- polars/ml/__init__.py +0 -0
- polars/ml/torch.py +0 -213
- polars/ml/utilities.py +0 -30
- polars/plugins.py +0 -155
- polars/py.typed +0 -0
- polars/pyproject.toml +0 -96
- polars/schema.py +0 -265
- polars/selectors.py +0 -3117
- polars/series/__init__.py +0 -5
- polars/series/array.py +0 -776
- polars/series/binary.py +0 -254
- polars/series/categorical.py +0 -246
- polars/series/datetime.py +0 -2275
- polars/series/list.py +0 -1087
- polars/series/plotting.py +0 -191
- polars/series/series.py +0 -9197
- polars/series/string.py +0 -2367
- polars/series/struct.py +0 -154
- polars/series/utils.py +0 -191
- polars/sql/__init__.py +0 -7
- polars/sql/context.py +0 -677
- polars/sql/functions.py +0 -139
- polars/string_cache.py +0 -185
- polars/testing/__init__.py +0 -13
- polars/testing/asserts/__init__.py +0 -9
- polars/testing/asserts/frame.py +0 -231
- polars/testing/asserts/series.py +0 -219
- polars/testing/asserts/utils.py +0 -12
- polars/testing/parametric/__init__.py +0 -33
- polars/testing/parametric/profiles.py +0 -107
- polars/testing/parametric/strategies/__init__.py +0 -22
- polars/testing/parametric/strategies/_utils.py +0 -14
- polars/testing/parametric/strategies/core.py +0 -615
- polars/testing/parametric/strategies/data.py +0 -452
- polars/testing/parametric/strategies/dtype.py +0 -436
- polars/testing/parametric/strategies/legacy.py +0 -169
- polars/type_aliases.py +0 -24
- polars_runtime_compat-1.34.0b2.dist-info/RECORD +0 -203
- {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/WHEEL +0 -0
- {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/licenses/LICENSE +0 -0
polars/expr/meta.py
DELETED
|
@@ -1,444 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING, Literal, overload
|
|
4
|
-
|
|
5
|
-
import polars._reexport as pl
|
|
6
|
-
from polars._utils.deprecation import deprecated
|
|
7
|
-
from polars._utils.serde import serialize_polars_object
|
|
8
|
-
from polars._utils.various import display_dot_graph
|
|
9
|
-
from polars._utils.wrap import wrap_expr
|
|
10
|
-
from polars.exceptions import ComputeError
|
|
11
|
-
|
|
12
|
-
if TYPE_CHECKING:
|
|
13
|
-
import sys
|
|
14
|
-
from io import IOBase
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
|
|
17
|
-
from polars import Expr
|
|
18
|
-
from polars._typing import SchemaDict, SerializationFormat
|
|
19
|
-
|
|
20
|
-
if sys.version_info >= (3, 13):
|
|
21
|
-
from warnings import deprecated
|
|
22
|
-
else:
|
|
23
|
-
from typing_extensions import deprecated # noqa: TC004
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class ExprMetaNameSpace:
|
|
27
|
-
"""Namespace for expressions on a meta level."""
|
|
28
|
-
|
|
29
|
-
_accessor = "meta"
|
|
30
|
-
|
|
31
|
-
def __init__(self, expr: Expr) -> None:
|
|
32
|
-
self._pyexpr = expr._pyexpr
|
|
33
|
-
|
|
34
|
-
def __eq__(self, other: ExprMetaNameSpace | Expr) -> bool: # type: ignore[override]
|
|
35
|
-
return self._pyexpr.meta_eq(other._pyexpr)
|
|
36
|
-
|
|
37
|
-
def __ne__(self, other: ExprMetaNameSpace | Expr) -> bool: # type: ignore[override]
|
|
38
|
-
return not self == other
|
|
39
|
-
|
|
40
|
-
def eq(self, other: ExprMetaNameSpace | Expr) -> bool:
|
|
41
|
-
"""
|
|
42
|
-
Indicate if this expression is the same as another expression.
|
|
43
|
-
|
|
44
|
-
Examples
|
|
45
|
-
--------
|
|
46
|
-
>>> foo_bar = pl.col("foo").alias("bar")
|
|
47
|
-
>>> foo = pl.col("foo")
|
|
48
|
-
>>> foo_bar.meta.eq(foo)
|
|
49
|
-
False
|
|
50
|
-
>>> foo_bar2 = pl.col("foo").alias("bar")
|
|
51
|
-
>>> foo_bar.meta.eq(foo_bar2)
|
|
52
|
-
True
|
|
53
|
-
"""
|
|
54
|
-
return self._pyexpr.meta_eq(other._pyexpr)
|
|
55
|
-
|
|
56
|
-
def ne(self, other: ExprMetaNameSpace | Expr) -> bool:
|
|
57
|
-
"""
|
|
58
|
-
Indicate if this expression is NOT the same as another expression.
|
|
59
|
-
|
|
60
|
-
Examples
|
|
61
|
-
--------
|
|
62
|
-
>>> foo_bar = pl.col("foo").alias("bar")
|
|
63
|
-
>>> foo = pl.col("foo")
|
|
64
|
-
>>> foo_bar.meta.ne(foo)
|
|
65
|
-
True
|
|
66
|
-
>>> foo_bar2 = pl.col("foo").alias("bar")
|
|
67
|
-
>>> foo_bar.meta.ne(foo_bar2)
|
|
68
|
-
False
|
|
69
|
-
"""
|
|
70
|
-
return not self.eq(other)
|
|
71
|
-
|
|
72
|
-
def has_multiple_outputs(self) -> bool:
|
|
73
|
-
"""
|
|
74
|
-
Indicate if this expression expands into multiple expressions.
|
|
75
|
-
|
|
76
|
-
Examples
|
|
77
|
-
--------
|
|
78
|
-
>>> e = pl.col(["a", "b"]).name.suffix("_foo")
|
|
79
|
-
>>> e.meta.has_multiple_outputs()
|
|
80
|
-
True
|
|
81
|
-
"""
|
|
82
|
-
return self._pyexpr.meta_has_multiple_outputs()
|
|
83
|
-
|
|
84
|
-
def is_column(self) -> bool:
|
|
85
|
-
r"""
|
|
86
|
-
Indicate if this expression is a basic (non-regex) unaliased column.
|
|
87
|
-
|
|
88
|
-
Examples
|
|
89
|
-
--------
|
|
90
|
-
>>> e = pl.col("foo")
|
|
91
|
-
>>> e.meta.is_column()
|
|
92
|
-
True
|
|
93
|
-
>>> e = pl.col("foo") * pl.col("bar")
|
|
94
|
-
>>> e.meta.is_column()
|
|
95
|
-
False
|
|
96
|
-
>>> e = pl.col(r"^col.*\d+$")
|
|
97
|
-
>>> e.meta.is_column()
|
|
98
|
-
False
|
|
99
|
-
"""
|
|
100
|
-
return self._pyexpr.meta_is_column()
|
|
101
|
-
|
|
102
|
-
def is_regex_projection(self) -> bool:
|
|
103
|
-
"""
|
|
104
|
-
Indicate if this expression expands to columns that match a regex pattern.
|
|
105
|
-
|
|
106
|
-
Examples
|
|
107
|
-
--------
|
|
108
|
-
>>> e = pl.col("^.*$").name.prefix("foo_")
|
|
109
|
-
>>> e.meta.is_regex_projection()
|
|
110
|
-
True
|
|
111
|
-
"""
|
|
112
|
-
return self._pyexpr.meta_is_regex_projection()
|
|
113
|
-
|
|
114
|
-
def is_column_selection(self, *, allow_aliasing: bool = False) -> bool:
|
|
115
|
-
"""
|
|
116
|
-
Indicate if this expression only selects columns (optionally with aliasing).
|
|
117
|
-
|
|
118
|
-
This can include bare columns, columns matched by regex or dtype, selectors
|
|
119
|
-
and exclude ops, and (optionally) column/expression aliasing.
|
|
120
|
-
|
|
121
|
-
.. versionadded:: 0.20.30
|
|
122
|
-
|
|
123
|
-
Parameters
|
|
124
|
-
----------
|
|
125
|
-
allow_aliasing
|
|
126
|
-
If False (default), any aliasing is not considered to be column selection.
|
|
127
|
-
Set True to allow for column selection that also includes aliasing.
|
|
128
|
-
|
|
129
|
-
Examples
|
|
130
|
-
--------
|
|
131
|
-
>>> import polars.selectors as cs
|
|
132
|
-
>>> e = pl.col("foo")
|
|
133
|
-
>>> e.meta.is_column_selection()
|
|
134
|
-
True
|
|
135
|
-
>>> e = pl.col("foo").alias("bar")
|
|
136
|
-
>>> e.meta.is_column_selection()
|
|
137
|
-
False
|
|
138
|
-
>>> e.meta.is_column_selection(allow_aliasing=True)
|
|
139
|
-
True
|
|
140
|
-
>>> e = pl.col("foo") * pl.col("bar")
|
|
141
|
-
>>> e.meta.is_column_selection()
|
|
142
|
-
False
|
|
143
|
-
>>> e = cs.starts_with("foo")
|
|
144
|
-
>>> e.meta.is_column_selection()
|
|
145
|
-
True
|
|
146
|
-
>>> e = cs.starts_with("foo").exclude("foo!")
|
|
147
|
-
>>> e.meta.is_column_selection()
|
|
148
|
-
True
|
|
149
|
-
"""
|
|
150
|
-
return self._pyexpr.meta_is_column_selection(allow_aliasing)
|
|
151
|
-
|
|
152
|
-
def is_literal(self, *, allow_aliasing: bool = False) -> bool:
|
|
153
|
-
"""
|
|
154
|
-
Indicate if this expression is a literal value (optionally aliased).
|
|
155
|
-
|
|
156
|
-
.. versionadded:: 1.14
|
|
157
|
-
|
|
158
|
-
Parameters
|
|
159
|
-
----------
|
|
160
|
-
allow_aliasing
|
|
161
|
-
If False (default), only a bare literal will match.
|
|
162
|
-
Set True to also allow for aliased literals.
|
|
163
|
-
|
|
164
|
-
Examples
|
|
165
|
-
--------
|
|
166
|
-
>>> from datetime import datetime
|
|
167
|
-
>>> e = pl.lit(123)
|
|
168
|
-
>>> e.meta.is_literal()
|
|
169
|
-
True
|
|
170
|
-
>>> e = pl.lit(987.654321).alias("foo")
|
|
171
|
-
>>> e.meta.is_literal()
|
|
172
|
-
False
|
|
173
|
-
>>> e = pl.lit(datetime.now()).alias("bar")
|
|
174
|
-
>>> e.meta.is_literal(allow_aliasing=True)
|
|
175
|
-
True
|
|
176
|
-
"""
|
|
177
|
-
return self._pyexpr.meta_is_literal(allow_aliasing)
|
|
178
|
-
|
|
179
|
-
@overload
|
|
180
|
-
def output_name(self, *, raise_if_undetermined: Literal[True] = True) -> str: ...
|
|
181
|
-
|
|
182
|
-
@overload
|
|
183
|
-
def output_name(self, *, raise_if_undetermined: Literal[False]) -> str | None: ...
|
|
184
|
-
|
|
185
|
-
def output_name(self, *, raise_if_undetermined: bool = True) -> str | None:
|
|
186
|
-
"""
|
|
187
|
-
Get the column name that this expression would produce.
|
|
188
|
-
|
|
189
|
-
It may not always be possible to determine the output name as that can depend
|
|
190
|
-
on the schema of the context; in that case this will raise `ComputeError` if
|
|
191
|
-
`raise_if_undetermined` is True (the default), or `None` otherwise.
|
|
192
|
-
|
|
193
|
-
Examples
|
|
194
|
-
--------
|
|
195
|
-
>>> e = pl.col("foo") * pl.col("bar")
|
|
196
|
-
>>> e.meta.output_name()
|
|
197
|
-
'foo'
|
|
198
|
-
>>> e_filter = pl.col("foo").filter(pl.col("bar") == 13)
|
|
199
|
-
>>> e_filter.meta.output_name()
|
|
200
|
-
'foo'
|
|
201
|
-
>>> e_sum_over = pl.sum("foo").over("groups")
|
|
202
|
-
>>> e_sum_over.meta.output_name()
|
|
203
|
-
'foo'
|
|
204
|
-
>>> e_sum_slice = pl.sum("foo").slice(pl.len() - 10, pl.col("bar"))
|
|
205
|
-
>>> e_sum_slice.meta.output_name()
|
|
206
|
-
'foo'
|
|
207
|
-
>>> pl.len().meta.output_name()
|
|
208
|
-
'len'
|
|
209
|
-
"""
|
|
210
|
-
try:
|
|
211
|
-
return self._pyexpr.meta_output_name()
|
|
212
|
-
except ComputeError:
|
|
213
|
-
if not raise_if_undetermined:
|
|
214
|
-
return None
|
|
215
|
-
raise
|
|
216
|
-
|
|
217
|
-
def pop(self, *, schema: SchemaDict | None = None) -> list[Expr]:
|
|
218
|
-
"""
|
|
219
|
-
Pop the latest expression and return the input(s) of the popped expression.
|
|
220
|
-
|
|
221
|
-
Returns
|
|
222
|
-
-------
|
|
223
|
-
list of Expr
|
|
224
|
-
A list of expressions which in most cases will have a unit length.
|
|
225
|
-
This is not the case when an expression has multiple inputs.
|
|
226
|
-
For instance in a `fold` expression.
|
|
227
|
-
|
|
228
|
-
Examples
|
|
229
|
-
--------
|
|
230
|
-
>>> e = pl.col("foo") + pl.col("bar")
|
|
231
|
-
>>> first = e.meta.pop()[0]
|
|
232
|
-
>>> first.meta == pl.col("bar")
|
|
233
|
-
True
|
|
234
|
-
>>> first.meta == pl.col("foo")
|
|
235
|
-
False
|
|
236
|
-
"""
|
|
237
|
-
return [wrap_expr(e) for e in self._pyexpr.meta_pop(schema)]
|
|
238
|
-
|
|
239
|
-
def root_names(self) -> list[str]:
|
|
240
|
-
"""
|
|
241
|
-
Get a list with the root column name.
|
|
242
|
-
|
|
243
|
-
Examples
|
|
244
|
-
--------
|
|
245
|
-
>>> e = pl.col("foo") * pl.col("bar")
|
|
246
|
-
>>> e.meta.root_names()
|
|
247
|
-
['foo', 'bar']
|
|
248
|
-
>>> e_filter = pl.col("foo").filter(pl.col("bar") == 13)
|
|
249
|
-
>>> e_filter.meta.root_names()
|
|
250
|
-
['foo', 'bar']
|
|
251
|
-
>>> e_sum_over = pl.sum("foo").over("groups")
|
|
252
|
-
>>> e_sum_over.meta.root_names()
|
|
253
|
-
['foo', 'groups']
|
|
254
|
-
>>> e_sum_slice = pl.sum("foo").slice(pl.len() - 10, pl.col("bar"))
|
|
255
|
-
>>> e_sum_slice.meta.root_names()
|
|
256
|
-
['foo', 'bar']
|
|
257
|
-
"""
|
|
258
|
-
return self._pyexpr.meta_root_names()
|
|
259
|
-
|
|
260
|
-
def undo_aliases(self) -> Expr:
|
|
261
|
-
"""
|
|
262
|
-
Undo any renaming operation like `alias` or `name.keep`.
|
|
263
|
-
|
|
264
|
-
Examples
|
|
265
|
-
--------
|
|
266
|
-
>>> e = pl.col("foo").alias("bar")
|
|
267
|
-
>>> e.meta.undo_aliases().meta == pl.col("foo")
|
|
268
|
-
True
|
|
269
|
-
>>> e = pl.col("foo").sum().over("bar")
|
|
270
|
-
>>> e.name.keep().meta.undo_aliases().meta == e
|
|
271
|
-
True
|
|
272
|
-
"""
|
|
273
|
-
return wrap_expr(self._pyexpr.meta_undo_aliases())
|
|
274
|
-
|
|
275
|
-
def as_selector(self) -> pl.Selector:
|
|
276
|
-
"""
|
|
277
|
-
Try to turn this expression in a selector.
|
|
278
|
-
|
|
279
|
-
Raises if the underlying expressions is not a column or selector.
|
|
280
|
-
|
|
281
|
-
.. warning::
|
|
282
|
-
This functionality is considered **unstable**. It may be changed
|
|
283
|
-
at any point without it being considered a breaking change.
|
|
284
|
-
"""
|
|
285
|
-
return pl.Selector._from_pyselector(self._pyexpr.into_selector())
|
|
286
|
-
|
|
287
|
-
@overload
|
|
288
|
-
def serialize(
|
|
289
|
-
self, file: None = ..., *, format: Literal["binary"] = ...
|
|
290
|
-
) -> bytes: ...
|
|
291
|
-
|
|
292
|
-
@overload
|
|
293
|
-
def serialize(self, file: None = ..., *, format: Literal["json"]) -> str: ...
|
|
294
|
-
|
|
295
|
-
@overload
|
|
296
|
-
def serialize(
|
|
297
|
-
self, file: IOBase | str | Path, *, format: SerializationFormat = ...
|
|
298
|
-
) -> None: ...
|
|
299
|
-
|
|
300
|
-
def serialize(
|
|
301
|
-
self,
|
|
302
|
-
file: IOBase | str | Path | None = None,
|
|
303
|
-
*,
|
|
304
|
-
format: SerializationFormat = "binary",
|
|
305
|
-
) -> bytes | str | None:
|
|
306
|
-
r"""
|
|
307
|
-
Serialize this expression to a file or string in JSON format.
|
|
308
|
-
|
|
309
|
-
Parameters
|
|
310
|
-
----------
|
|
311
|
-
file
|
|
312
|
-
File path to which the result should be written. If set to `None`
|
|
313
|
-
(default), the output is returned as a string instead.
|
|
314
|
-
format
|
|
315
|
-
The format in which to serialize. Options:
|
|
316
|
-
|
|
317
|
-
- `"binary"`: Serialize to binary format (bytes). This is the default.
|
|
318
|
-
- `"json"`: Serialize to JSON format (string).
|
|
319
|
-
|
|
320
|
-
See Also
|
|
321
|
-
--------
|
|
322
|
-
Expr.deserialize
|
|
323
|
-
|
|
324
|
-
Notes
|
|
325
|
-
-----
|
|
326
|
-
Serialization is not stable across Polars versions: a LazyFrame serialized
|
|
327
|
-
in one Polars version may not be deserializable in another Polars version.
|
|
328
|
-
|
|
329
|
-
Examples
|
|
330
|
-
--------
|
|
331
|
-
Serialize the expression into a binary representation.
|
|
332
|
-
|
|
333
|
-
>>> expr = pl.col("foo").sum().over("bar")
|
|
334
|
-
>>> bytes = expr.meta.serialize()
|
|
335
|
-
>>> type(bytes)
|
|
336
|
-
<class 'bytes'>
|
|
337
|
-
|
|
338
|
-
The bytes can later be deserialized back into an `Expr` object.
|
|
339
|
-
|
|
340
|
-
>>> import io
|
|
341
|
-
>>> pl.Expr.deserialize(io.BytesIO(bytes))
|
|
342
|
-
<Expr ['col("foo").sum().over([col("ba…'] at ...>
|
|
343
|
-
"""
|
|
344
|
-
if format == "binary":
|
|
345
|
-
serializer = self._pyexpr.serialize_binary
|
|
346
|
-
elif format == "json":
|
|
347
|
-
serializer = self._pyexpr.serialize_json
|
|
348
|
-
else:
|
|
349
|
-
msg = f"`format` must be one of {{'binary', 'json'}}, got {format!r}"
|
|
350
|
-
raise ValueError(msg)
|
|
351
|
-
|
|
352
|
-
return serialize_polars_object(serializer, file, format)
|
|
353
|
-
|
|
354
|
-
@overload
|
|
355
|
-
def write_json(self, file: None = ...) -> str: ...
|
|
356
|
-
|
|
357
|
-
@overload
|
|
358
|
-
def write_json(self, file: IOBase | str | Path) -> None: ...
|
|
359
|
-
|
|
360
|
-
@deprecated("`meta.write_json` was renamed; use `meta.serialize` instead")
|
|
361
|
-
def write_json(self, file: IOBase | str | Path | None = None) -> str | None:
|
|
362
|
-
"""
|
|
363
|
-
Write expression to json.
|
|
364
|
-
|
|
365
|
-
.. deprecated:: 0.20.11
|
|
366
|
-
This method has been renamed to :meth:`serialize`.
|
|
367
|
-
"""
|
|
368
|
-
return self.serialize(file, format="json")
|
|
369
|
-
|
|
370
|
-
@overload
|
|
371
|
-
def tree_format(
|
|
372
|
-
self,
|
|
373
|
-
*,
|
|
374
|
-
return_as_string: Literal[False] = ...,
|
|
375
|
-
schema: None | SchemaDict = None,
|
|
376
|
-
) -> None: ...
|
|
377
|
-
|
|
378
|
-
@overload
|
|
379
|
-
def tree_format(
|
|
380
|
-
self, *, return_as_string: Literal[True], schema: None | SchemaDict = None
|
|
381
|
-
) -> str: ...
|
|
382
|
-
|
|
383
|
-
def tree_format(
|
|
384
|
-
self, *, return_as_string: bool = False, schema: None | SchemaDict = None
|
|
385
|
-
) -> str | None:
|
|
386
|
-
"""
|
|
387
|
-
Format the expression as a tree.
|
|
388
|
-
|
|
389
|
-
Parameters
|
|
390
|
-
----------
|
|
391
|
-
return_as_string:
|
|
392
|
-
If True, return as string rather than printing to stdout.
|
|
393
|
-
|
|
394
|
-
Examples
|
|
395
|
-
--------
|
|
396
|
-
>>> e = (pl.col("foo") * pl.col("bar")).sum().over(pl.col("ham")) / 2
|
|
397
|
-
>>> e.meta.tree_format(return_as_string=True) # doctest: +SKIP
|
|
398
|
-
"""
|
|
399
|
-
s = self._pyexpr.meta_tree_format(schema)
|
|
400
|
-
if return_as_string:
|
|
401
|
-
return s
|
|
402
|
-
else:
|
|
403
|
-
print(s)
|
|
404
|
-
return None
|
|
405
|
-
|
|
406
|
-
def show_graph(
|
|
407
|
-
self,
|
|
408
|
-
*,
|
|
409
|
-
show: bool = True,
|
|
410
|
-
output_path: str | Path | None = None,
|
|
411
|
-
raw_output: bool = False,
|
|
412
|
-
figsize: tuple[float, float] = (16.0, 12.0),
|
|
413
|
-
schema: None | SchemaDict = None,
|
|
414
|
-
) -> str | None:
|
|
415
|
-
"""
|
|
416
|
-
Format the expression as a Graphviz graph.
|
|
417
|
-
|
|
418
|
-
Note that Graphviz must be installed to render the visualization (if not
|
|
419
|
-
already present, you can download it here: `<https://graphviz.org/download>`_).
|
|
420
|
-
|
|
421
|
-
Parameters
|
|
422
|
-
----------
|
|
423
|
-
show
|
|
424
|
-
Show the figure.
|
|
425
|
-
output_path
|
|
426
|
-
Write the figure to disk.
|
|
427
|
-
raw_output
|
|
428
|
-
Return dot syntax. This cannot be combined with `show` and/or `output_path`.
|
|
429
|
-
figsize
|
|
430
|
-
Passed to matplotlib if `show == True`.
|
|
431
|
-
|
|
432
|
-
Examples
|
|
433
|
-
--------
|
|
434
|
-
>>> e = (pl.col("foo") * pl.col("bar")).sum().over(pl.col("ham")) / 2
|
|
435
|
-
>>> e.meta.show_graph() # doctest: +SKIP
|
|
436
|
-
"""
|
|
437
|
-
dot = self._pyexpr.meta_show_graph(schema)
|
|
438
|
-
return display_dot_graph(
|
|
439
|
-
dot=dot,
|
|
440
|
-
show=show,
|
|
441
|
-
output_path=output_path,
|
|
442
|
-
raw_output=raw_output,
|
|
443
|
-
figsize=figsize,
|
|
444
|
-
)
|