polars-runtime-compat 1.34.0b2__cp39-abi3-manylinux_2_24_aarch64.whl → 1.34.0b4__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/_polars_runtime_compat.abi3.so +0 -0
  2. {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/METADATA +1 -1
  3. polars_runtime_compat-1.34.0b4.dist-info/RECORD +6 -0
  4. polars/__init__.py +0 -528
  5. polars/_cpu_check.py +0 -265
  6. polars/_dependencies.py +0 -355
  7. polars/_plr.py +0 -99
  8. polars/_plr.pyi +0 -2496
  9. polars/_reexport.py +0 -23
  10. polars/_typing.py +0 -478
  11. polars/_utils/__init__.py +0 -37
  12. polars/_utils/async_.py +0 -102
  13. polars/_utils/cache.py +0 -176
  14. polars/_utils/cloud.py +0 -40
  15. polars/_utils/constants.py +0 -29
  16. polars/_utils/construction/__init__.py +0 -46
  17. polars/_utils/construction/dataframe.py +0 -1397
  18. polars/_utils/construction/other.py +0 -72
  19. polars/_utils/construction/series.py +0 -560
  20. polars/_utils/construction/utils.py +0 -118
  21. polars/_utils/convert.py +0 -224
  22. polars/_utils/deprecation.py +0 -406
  23. polars/_utils/getitem.py +0 -457
  24. polars/_utils/logging.py +0 -11
  25. polars/_utils/nest_asyncio.py +0 -264
  26. polars/_utils/parquet.py +0 -15
  27. polars/_utils/parse/__init__.py +0 -12
  28. polars/_utils/parse/expr.py +0 -242
  29. polars/_utils/polars_version.py +0 -19
  30. polars/_utils/pycapsule.py +0 -53
  31. polars/_utils/scan.py +0 -27
  32. polars/_utils/serde.py +0 -63
  33. polars/_utils/slice.py +0 -215
  34. polars/_utils/udfs.py +0 -1251
  35. polars/_utils/unstable.py +0 -63
  36. polars/_utils/various.py +0 -782
  37. polars/_utils/wrap.py +0 -25
  38. polars/api.py +0 -370
  39. polars/catalog/__init__.py +0 -0
  40. polars/catalog/unity/__init__.py +0 -19
  41. polars/catalog/unity/client.py +0 -733
  42. polars/catalog/unity/models.py +0 -152
  43. polars/config.py +0 -1571
  44. polars/convert/__init__.py +0 -25
  45. polars/convert/general.py +0 -1046
  46. polars/convert/normalize.py +0 -261
  47. polars/dataframe/__init__.py +0 -5
  48. polars/dataframe/_html.py +0 -186
  49. polars/dataframe/frame.py +0 -12582
  50. polars/dataframe/group_by.py +0 -1067
  51. polars/dataframe/plotting.py +0 -257
  52. polars/datatype_expr/__init__.py +0 -5
  53. polars/datatype_expr/array.py +0 -56
  54. polars/datatype_expr/datatype_expr.py +0 -304
  55. polars/datatype_expr/list.py +0 -18
  56. polars/datatype_expr/struct.py +0 -69
  57. polars/datatypes/__init__.py +0 -122
  58. polars/datatypes/_parse.py +0 -195
  59. polars/datatypes/_utils.py +0 -48
  60. polars/datatypes/classes.py +0 -1213
  61. polars/datatypes/constants.py +0 -11
  62. polars/datatypes/constructor.py +0 -172
  63. polars/datatypes/convert.py +0 -366
  64. polars/datatypes/group.py +0 -130
  65. polars/exceptions.py +0 -230
  66. polars/expr/__init__.py +0 -7
  67. polars/expr/array.py +0 -964
  68. polars/expr/binary.py +0 -346
  69. polars/expr/categorical.py +0 -306
  70. polars/expr/datetime.py +0 -2620
  71. polars/expr/expr.py +0 -11272
  72. polars/expr/list.py +0 -1408
  73. polars/expr/meta.py +0 -444
  74. polars/expr/name.py +0 -321
  75. polars/expr/string.py +0 -3045
  76. polars/expr/struct.py +0 -357
  77. polars/expr/whenthen.py +0 -185
  78. polars/functions/__init__.py +0 -193
  79. polars/functions/aggregation/__init__.py +0 -33
  80. polars/functions/aggregation/horizontal.py +0 -298
  81. polars/functions/aggregation/vertical.py +0 -341
  82. polars/functions/as_datatype.py +0 -848
  83. polars/functions/business.py +0 -138
  84. polars/functions/col.py +0 -384
  85. polars/functions/datatype.py +0 -121
  86. polars/functions/eager.py +0 -524
  87. polars/functions/escape_regex.py +0 -29
  88. polars/functions/lazy.py +0 -2751
  89. polars/functions/len.py +0 -68
  90. polars/functions/lit.py +0 -210
  91. polars/functions/random.py +0 -22
  92. polars/functions/range/__init__.py +0 -19
  93. polars/functions/range/_utils.py +0 -15
  94. polars/functions/range/date_range.py +0 -303
  95. polars/functions/range/datetime_range.py +0 -370
  96. polars/functions/range/int_range.py +0 -348
  97. polars/functions/range/linear_space.py +0 -311
  98. polars/functions/range/time_range.py +0 -287
  99. polars/functions/repeat.py +0 -301
  100. polars/functions/whenthen.py +0 -353
  101. polars/interchange/__init__.py +0 -10
  102. polars/interchange/buffer.py +0 -77
  103. polars/interchange/column.py +0 -190
  104. polars/interchange/dataframe.py +0 -230
  105. polars/interchange/from_dataframe.py +0 -328
  106. polars/interchange/protocol.py +0 -303
  107. polars/interchange/utils.py +0 -170
  108. polars/io/__init__.py +0 -64
  109. polars/io/_utils.py +0 -317
  110. polars/io/avro.py +0 -49
  111. polars/io/clipboard.py +0 -36
  112. polars/io/cloud/__init__.py +0 -17
  113. polars/io/cloud/_utils.py +0 -80
  114. polars/io/cloud/credential_provider/__init__.py +0 -17
  115. polars/io/cloud/credential_provider/_builder.py +0 -520
  116. polars/io/cloud/credential_provider/_providers.py +0 -618
  117. polars/io/csv/__init__.py +0 -9
  118. polars/io/csv/_utils.py +0 -38
  119. polars/io/csv/batched_reader.py +0 -142
  120. polars/io/csv/functions.py +0 -1495
  121. polars/io/database/__init__.py +0 -6
  122. polars/io/database/_arrow_registry.py +0 -70
  123. polars/io/database/_cursor_proxies.py +0 -147
  124. polars/io/database/_executor.py +0 -578
  125. polars/io/database/_inference.py +0 -314
  126. polars/io/database/_utils.py +0 -144
  127. polars/io/database/functions.py +0 -516
  128. polars/io/delta.py +0 -499
  129. polars/io/iceberg/__init__.py +0 -3
  130. polars/io/iceberg/_utils.py +0 -697
  131. polars/io/iceberg/dataset.py +0 -556
  132. polars/io/iceberg/functions.py +0 -151
  133. polars/io/ipc/__init__.py +0 -8
  134. polars/io/ipc/functions.py +0 -514
  135. polars/io/json/__init__.py +0 -3
  136. polars/io/json/read.py +0 -101
  137. polars/io/ndjson.py +0 -332
  138. polars/io/parquet/__init__.py +0 -17
  139. polars/io/parquet/field_overwrites.py +0 -140
  140. polars/io/parquet/functions.py +0 -722
  141. polars/io/partition.py +0 -491
  142. polars/io/plugins.py +0 -187
  143. polars/io/pyarrow_dataset/__init__.py +0 -5
  144. polars/io/pyarrow_dataset/anonymous_scan.py +0 -109
  145. polars/io/pyarrow_dataset/functions.py +0 -79
  146. polars/io/scan_options/__init__.py +0 -5
  147. polars/io/scan_options/_options.py +0 -59
  148. polars/io/scan_options/cast_options.py +0 -126
  149. polars/io/spreadsheet/__init__.py +0 -6
  150. polars/io/spreadsheet/_utils.py +0 -52
  151. polars/io/spreadsheet/_write_utils.py +0 -647
  152. polars/io/spreadsheet/functions.py +0 -1323
  153. polars/lazyframe/__init__.py +0 -9
  154. polars/lazyframe/engine_config.py +0 -61
  155. polars/lazyframe/frame.py +0 -8564
  156. polars/lazyframe/group_by.py +0 -669
  157. polars/lazyframe/in_process.py +0 -42
  158. polars/lazyframe/opt_flags.py +0 -333
  159. polars/meta/__init__.py +0 -14
  160. polars/meta/build.py +0 -33
  161. polars/meta/index_type.py +0 -27
  162. polars/meta/thread_pool.py +0 -50
  163. polars/meta/versions.py +0 -120
  164. polars/ml/__init__.py +0 -0
  165. polars/ml/torch.py +0 -213
  166. polars/ml/utilities.py +0 -30
  167. polars/plugins.py +0 -155
  168. polars/py.typed +0 -0
  169. polars/pyproject.toml +0 -96
  170. polars/schema.py +0 -265
  171. polars/selectors.py +0 -3117
  172. polars/series/__init__.py +0 -5
  173. polars/series/array.py +0 -776
  174. polars/series/binary.py +0 -254
  175. polars/series/categorical.py +0 -246
  176. polars/series/datetime.py +0 -2275
  177. polars/series/list.py +0 -1087
  178. polars/series/plotting.py +0 -191
  179. polars/series/series.py +0 -9197
  180. polars/series/string.py +0 -2367
  181. polars/series/struct.py +0 -154
  182. polars/series/utils.py +0 -191
  183. polars/sql/__init__.py +0 -7
  184. polars/sql/context.py +0 -677
  185. polars/sql/functions.py +0 -139
  186. polars/string_cache.py +0 -185
  187. polars/testing/__init__.py +0 -13
  188. polars/testing/asserts/__init__.py +0 -9
  189. polars/testing/asserts/frame.py +0 -231
  190. polars/testing/asserts/series.py +0 -219
  191. polars/testing/asserts/utils.py +0 -12
  192. polars/testing/parametric/__init__.py +0 -33
  193. polars/testing/parametric/profiles.py +0 -107
  194. polars/testing/parametric/strategies/__init__.py +0 -22
  195. polars/testing/parametric/strategies/_utils.py +0 -14
  196. polars/testing/parametric/strategies/core.py +0 -615
  197. polars/testing/parametric/strategies/data.py +0 -452
  198. polars/testing/parametric/strategies/dtype.py +0 -436
  199. polars/testing/parametric/strategies/legacy.py +0 -169
  200. polars/type_aliases.py +0 -24
  201. polars_runtime_compat-1.34.0b2.dist-info/RECORD +0 -203
  202. {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/WHEEL +0 -0
  203. {polars_runtime_compat-1.34.0b2.dist-info → polars_runtime_compat-1.34.0b4.dist-info}/licenses/LICENSE +0 -0
@@ -1,138 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import contextlib
4
- from datetime import date
5
- from typing import TYPE_CHECKING
6
-
7
- from polars._utils.deprecation import deprecate_nonkeyword_arguments
8
- from polars._utils.parse import parse_into_expression
9
- from polars._utils.unstable import unstable
10
- from polars._utils.wrap import wrap_expr
11
-
12
- with contextlib.suppress(ImportError): # Module not available when building docs
13
- import polars._plr as plr
14
-
15
- if TYPE_CHECKING:
16
- from collections.abc import Iterable
17
-
18
- from polars import Expr
19
- from polars._typing import IntoExprColumn
20
-
21
-
22
- @unstable()
23
- @deprecate_nonkeyword_arguments(allowed_args=["start", "end"], version="1.27.0")
24
- def business_day_count(
25
- start: date | IntoExprColumn,
26
- end: date | IntoExprColumn,
27
- week_mask: Iterable[bool] = (True, True, True, True, True, False, False),
28
- holidays: Iterable[date] = (),
29
- ) -> Expr:
30
- """
31
- Count the number of business days between `start` and `end` (not including `end`).
32
-
33
- .. warning::
34
- This functionality is considered **unstable**. It may be changed
35
- at any point without it being considered a breaking change.
36
-
37
- .. versionchanged:: 1.27.0
38
- Parameters after `start` and `end` should now be passed as keyword arguments.
39
-
40
- Parameters
41
- ----------
42
- start
43
- Start dates.
44
- end
45
- End dates.
46
- week_mask
47
- Which days of the week to count. The default is Monday to Friday.
48
- If you wanted to count only Monday to Thursday, you would pass
49
- `(True, True, True, True, False, False, False)`.
50
- holidays
51
- Holidays to exclude from the count. The Python package
52
- `python-holidays <https://github.com/vacanza/python-holidays>`_
53
- may come in handy here. You can install it with ``pip install holidays``,
54
- and then, to get all Dutch holidays for years 2020-2024:
55
-
56
- .. code-block:: python
57
-
58
- import holidays
59
-
60
- my_holidays = holidays.country_holidays("NL", years=range(2020, 2025))
61
-
62
- and pass `holidays=my_holidays` when you call `business_day_count`.
63
-
64
- Returns
65
- -------
66
- Expr
67
-
68
- Examples
69
- --------
70
- >>> from datetime import date
71
- >>> df = pl.DataFrame(
72
- ... {
73
- ... "start": [date(2020, 1, 1), date(2020, 1, 2)],
74
- ... "end": [date(2020, 1, 2), date(2020, 1, 10)],
75
- ... }
76
- ... )
77
- >>> df.with_columns(
78
- ... business_day_count=pl.business_day_count("start", "end"),
79
- ... )
80
- shape: (2, 3)
81
- ┌────────────┬────────────┬────────────────────┐
82
- │ start ┆ end ┆ business_day_count │
83
- │ --- ┆ --- ┆ --- │
84
- │ date ┆ date ┆ i32 │
85
- ╞════════════╪════════════╪════════════════════╡
86
- │ 2020-01-01 ┆ 2020-01-02 ┆ 1 │
87
- │ 2020-01-02 ┆ 2020-01-10 ┆ 6 │
88
- └────────────┴────────────┴────────────────────┘
89
-
90
- Note how the business day count is 6 (as opposed a regular day count of 8)
91
- due to the weekend (2020-01-04 - 2020-01-05) not being counted.
92
-
93
- You can pass a custom weekend - for example, if you only take Sunday off:
94
-
95
- >>> week_mask = (True, True, True, True, True, True, False)
96
- >>> df.with_columns(
97
- ... business_day_count=pl.business_day_count(
98
- ... "start", "end", week_mask=week_mask
99
- ... ),
100
- ... )
101
- shape: (2, 3)
102
- ┌────────────┬────────────┬────────────────────┐
103
- │ start ┆ end ┆ business_day_count │
104
- │ --- ┆ --- ┆ --- │
105
- │ date ┆ date ┆ i32 │
106
- ╞════════════╪════════════╪════════════════════╡
107
- │ 2020-01-01 ┆ 2020-01-02 ┆ 1 │
108
- │ 2020-01-02 ┆ 2020-01-10 ┆ 7 │
109
- └────────────┴────────────┴────────────────────┘
110
-
111
- You can also pass a list of holidays to exclude from the count:
112
-
113
- >>> from datetime import date
114
- >>> holidays = [date(2020, 1, 1), date(2020, 1, 2)]
115
- >>> df.with_columns(
116
- ... business_day_count=pl.business_day_count("start", "end", holidays=holidays)
117
- ... )
118
- shape: (2, 3)
119
- ┌────────────┬────────────┬────────────────────┐
120
- │ start ┆ end ┆ business_day_count │
121
- │ --- ┆ --- ┆ --- │
122
- │ date ┆ date ┆ i32 │
123
- ╞════════════╪════════════╪════════════════════╡
124
- │ 2020-01-01 ┆ 2020-01-02 ┆ 0 │
125
- │ 2020-01-02 ┆ 2020-01-10 ┆ 5 │
126
- └────────────┴────────────┴────────────────────┘
127
- """
128
- start_pyexpr = parse_into_expression(start)
129
- end_pyexpr = parse_into_expression(end)
130
- unix_epoch = date(1970, 1, 1)
131
- return wrap_expr(
132
- plr.business_day_count(
133
- start_pyexpr,
134
- end_pyexpr,
135
- list(week_mask),
136
- [(holiday - unix_epoch).days for holiday in holidays],
137
- )
138
- )
polars/functions/col.py DELETED
@@ -1,384 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import contextlib
4
- import sys
5
- from collections.abc import Iterable
6
- from datetime import datetime, timedelta
7
- from typing import TYPE_CHECKING
8
-
9
- import polars._reexport as pl
10
- from polars._utils.wrap import wrap_expr
11
- from polars.datatypes import (
12
- Datetime,
13
- Duration,
14
- is_polars_dtype,
15
- parse_into_dtype,
16
- )
17
- from polars.datatypes.group import (
18
- DATETIME_DTYPES,
19
- DURATION_DTYPES,
20
- FLOAT_DTYPES,
21
- INTEGER_DTYPES,
22
- )
23
-
24
- with contextlib.suppress(ImportError): # Module not available when building docs
25
- import polars._plr as plr
26
-
27
- if TYPE_CHECKING:
28
- from polars._typing import PolarsDataType, PythonDataType
29
- from polars.expr.expr import Expr
30
-
31
- if not sys.version_info >= (3, 11):
32
- from typing import Any
33
-
34
- __all__ = ["col"]
35
-
36
-
37
- def _create_col(
38
- name: (
39
- str
40
- | PolarsDataType
41
- | PythonDataType
42
- | Iterable[str]
43
- | Iterable[PolarsDataType | PythonDataType]
44
- ),
45
- *more_names: str | PolarsDataType | PythonDataType,
46
- ) -> Expr:
47
- """Create one or more column expressions representing column(s) in a DataFrame."""
48
- dtypes: list[PolarsDataType]
49
- if more_names:
50
- if isinstance(name, str):
51
- names_str = [name]
52
- names_str.extend(more_names) # type: ignore[arg-type]
53
- return pl.Selector._by_name(names_str, strict=True).as_expr()
54
- elif is_polars_dtype(name):
55
- dtypes = [name]
56
- dtypes.extend(more_names) # type: ignore[arg-type]
57
- return pl.Selector._by_dtype(dtypes).as_expr() # type: ignore[arg-type]
58
- else:
59
- msg = (
60
- "invalid input for `col`"
61
- f"\n\nExpected `str` or `DataType`, got {type(name).__name__!r}."
62
- )
63
- raise TypeError(msg)
64
-
65
- if isinstance(name, str):
66
- return wrap_expr(plr.col(name))
67
- elif is_polars_dtype(name):
68
- dtypes = _polars_dtype_match(name)
69
- return pl.Selector._by_dtype(dtypes).as_expr() # type: ignore[arg-type]
70
- elif isinstance(name, type):
71
- dtypes = _python_dtype_match(name)
72
- return pl.Selector._by_dtype(dtypes).as_expr() # type: ignore[arg-type]
73
- elif isinstance(name, Iterable):
74
- names = list(name)
75
- if not names:
76
- return pl.Selector._by_name(names, strict=True).as_expr() # type: ignore[arg-type]
77
-
78
- item = names[0]
79
- if isinstance(item, str):
80
- return pl.Selector._by_name(names, strict=True).as_expr() # type: ignore[arg-type]
81
- elif is_polars_dtype(item):
82
- dtypes = []
83
- for nm in names:
84
- dtypes.extend(_polars_dtype_match(nm)) # type: ignore[arg-type]
85
- return pl.Selector._by_dtype(dtypes).as_expr() # type: ignore[arg-type]
86
- elif isinstance(item, type):
87
- dtypes = []
88
- for nm in names:
89
- dtypes.extend(_python_dtype_match(nm)) # type: ignore[arg-type]
90
- return pl.Selector._by_dtype(dtypes).as_expr() # type: ignore[arg-type]
91
- else:
92
- msg = (
93
- "invalid input for `col`"
94
- "\n\nExpected iterable of type `str` or `DataType`,"
95
- f" got iterable of type {type(item).__name__!r}."
96
- )
97
- raise TypeError(msg)
98
- else:
99
- msg = (
100
- "invalid input for `col`"
101
- f"\n\nExpected `str` or `DataType`, got {type(name).__name__!r}."
102
- )
103
- raise TypeError(msg)
104
-
105
-
106
- def _python_dtype_match(tp: PythonDataType) -> list[PolarsDataType]:
107
- if tp is int:
108
- return list(INTEGER_DTYPES)
109
- elif tp is float:
110
- return list(FLOAT_DTYPES)
111
- elif tp is datetime:
112
- return list(DATETIME_DTYPES)
113
- elif tp is timedelta:
114
- return list(DURATION_DTYPES)
115
- return [parse_into_dtype(tp)]
116
-
117
-
118
- def _polars_dtype_match(tp: PolarsDataType) -> list[PolarsDataType]:
119
- if Datetime.is_(tp):
120
- return list(DATETIME_DTYPES)
121
- elif Duration.is_(tp):
122
- return list(DURATION_DTYPES)
123
- return [tp]
124
-
125
-
126
- class Col:
127
- """
128
- Create Polars column expressions.
129
-
130
- Notes
131
- -----
132
- An instance of this class is exported under the name `col`. It can be used as
133
- though it were a function by calling, for example, `pl.col("foo")`.
134
- See the :func:`__call__` method for further documentation.
135
-
136
- This helper class enables an alternative syntax for creating a column expression
137
- through attribute lookup. For example `col.foo` creates an expression equal to
138
- `col("foo")`. See the :func:`__getattr__` method for further documentation.
139
-
140
- The function call syntax is considered the idiomatic way of constructing a column
141
- expression. The alternative attribute syntax can be useful for quick prototyping as
142
- it can save some keystrokes, but has drawbacks in both expressiveness and
143
- readability.
144
-
145
- Examples
146
- --------
147
- >>> from polars import col
148
- >>> df = pl.DataFrame(
149
- ... {
150
- ... "foo": [1, 2],
151
- ... "bar": [3, 4],
152
- ... }
153
- ... )
154
-
155
- Create a new column expression using the standard syntax:
156
-
157
- >>> df.with_columns(baz=(col("foo") * col("bar")) / 2)
158
- shape: (2, 3)
159
- ┌─────┬─────┬─────┐
160
- │ foo ┆ bar ┆ baz │
161
- │ --- ┆ --- ┆ --- │
162
- │ i64 ┆ i64 ┆ f64 │
163
- ╞═════╪═════╪═════╡
164
- │ 1 ┆ 3 ┆ 1.5 │
165
- │ 2 ┆ 4 ┆ 4.0 │
166
- └─────┴─────┴─────┘
167
-
168
- Use attribute lookup to create a new column expression:
169
-
170
- >>> df.with_columns(baz=(col.foo + col.bar))
171
- shape: (2, 3)
172
- ┌─────┬─────┬─────┐
173
- │ foo ┆ bar ┆ baz │
174
- │ --- ┆ --- ┆ --- │
175
- │ i64 ┆ i64 ┆ i64 │
176
- ╞═════╪═════╪═════╡
177
- │ 1 ┆ 3 ┆ 4 │
178
- │ 2 ┆ 4 ┆ 6 │
179
- └─────┴─────┴─────┘
180
- """
181
-
182
- def __call__(
183
- self,
184
- name: (
185
- str
186
- | PolarsDataType
187
- | PythonDataType
188
- | Iterable[str]
189
- | Iterable[PolarsDataType | PythonDataType]
190
- ),
191
- *more_names: str | PolarsDataType | PythonDataType,
192
- ) -> Expr:
193
- """
194
- Create one or more expressions representing columns in a DataFrame.
195
-
196
- Parameters
197
- ----------
198
- name
199
- The name or datatype of the column(s) to represent.
200
- Accepts regular expression input; regular expressions
201
- should start with `^` and end with `$`.
202
- *more_names
203
- Additional names or datatypes of columns to represent,
204
- specified as positional arguments.
205
-
206
- See Also
207
- --------
208
- first
209
- last
210
- nth
211
-
212
- Examples
213
- --------
214
- Pass a single column name to represent that column.
215
-
216
- >>> df = pl.DataFrame(
217
- ... {
218
- ... "ham": [1, 2],
219
- ... "hamburger": [11, 22],
220
- ... "foo": [2, 1],
221
- ... "bar": ["a", "b"],
222
- ... }
223
- ... )
224
- >>> df.select(pl.col("foo"))
225
- shape: (2, 1)
226
- ┌─────┐
227
- │ foo │
228
- │ --- │
229
- │ i64 │
230
- ╞═════╡
231
- │ 2 │
232
- │ 1 │
233
- └─────┘
234
-
235
- Use dot syntax to save keystrokes for quick prototyping.
236
-
237
- >>> from polars import col as c
238
- >>> df.select(c.foo + c.ham)
239
- shape: (2, 1)
240
- ┌─────┐
241
- │ foo │
242
- │ --- │
243
- │ i64 │
244
- ╞═════╡
245
- │ 3 │
246
- │ 3 │
247
- └─────┘
248
-
249
- Use the wildcard `*` to represent all columns.
250
-
251
- >>> df.select(pl.col("*"))
252
- shape: (2, 4)
253
- ┌─────┬───────────┬─────┬─────┐
254
- │ ham ┆ hamburger ┆ foo ┆ bar │
255
- │ --- ┆ --- ┆ --- ┆ --- │
256
- │ i64 ┆ i64 ┆ i64 ┆ str │
257
- ╞═════╪═══════════╪═════╪═════╡
258
- │ 1 ┆ 11 ┆ 2 ┆ a │
259
- │ 2 ┆ 22 ┆ 1 ┆ b │
260
- └─────┴───────────┴─────┴─────┘
261
- >>> df.select(pl.col("*").exclude("ham"))
262
- shape: (2, 3)
263
- ┌───────────┬─────┬─────┐
264
- │ hamburger ┆ foo ┆ bar │
265
- │ --- ┆ --- ┆ --- │
266
- │ i64 ┆ i64 ┆ str │
267
- ╞═══════════╪═════╪═════╡
268
- │ 11 ┆ 2 ┆ a │
269
- │ 22 ┆ 1 ┆ b │
270
- └───────────┴─────┴─────┘
271
-
272
- Regular expression input is supported.
273
-
274
- >>> df.select(pl.col("^ham.*$"))
275
- shape: (2, 2)
276
- ┌─────┬───────────┐
277
- │ ham ┆ hamburger │
278
- │ --- ┆ --- │
279
- │ i64 ┆ i64 │
280
- ╞═════╪═══════════╡
281
- │ 1 ┆ 11 │
282
- │ 2 ┆ 22 │
283
- └─────┴───────────┘
284
-
285
- Multiple columns can be represented by passing a list of names.
286
-
287
- >>> df.select(pl.col(["hamburger", "foo"]))
288
- shape: (2, 2)
289
- ┌───────────┬─────┐
290
- │ hamburger ┆ foo │
291
- │ --- ┆ --- │
292
- │ i64 ┆ i64 │
293
- ╞═══════════╪═════╡
294
- │ 11 ┆ 2 │
295
- │ 22 ┆ 1 │
296
- └───────────┴─────┘
297
-
298
- Or use positional arguments to represent multiple columns in the same way.
299
-
300
- >>> df.select(pl.col("hamburger", "foo"))
301
- shape: (2, 2)
302
- ┌───────────┬─────┐
303
- │ hamburger ┆ foo │
304
- │ --- ┆ --- │
305
- │ i64 ┆ i64 │
306
- ╞═══════════╪═════╡
307
- │ 11 ┆ 2 │
308
- │ 22 ┆ 1 │
309
- └───────────┴─────┘
310
-
311
- Easily select all columns that match a certain data type by passing that
312
- datatype.
313
-
314
- >>> df.select(pl.col(pl.String))
315
- shape: (2, 1)
316
- ┌─────┐
317
- │ bar │
318
- │ --- │
319
- │ str │
320
- ╞═════╡
321
- │ a │
322
- │ b │
323
- └─────┘
324
- >>> df.select(pl.col(pl.Int64, pl.Float64))
325
- shape: (2, 3)
326
- ┌─────┬───────────┬─────┐
327
- │ ham ┆ hamburger ┆ foo │
328
- │ --- ┆ --- ┆ --- │
329
- │ i64 ┆ i64 ┆ i64 │
330
- ╞═════╪═══════════╪═════╡
331
- │ 1 ┆ 11 ┆ 2 │
332
- │ 2 ┆ 22 ┆ 1 │
333
- └─────┴───────────┴─────┘
334
- """
335
- return _create_col(name, *more_names)
336
-
337
- def __getattr__(self, name: str) -> Expr:
338
- """
339
- Create a column expression using attribute syntax.
340
-
341
- Note that this syntax does not support passing data
342
- types or multiple column names.
343
-
344
- Parameters
345
- ----------
346
- name
347
- The name of the column to represent.
348
-
349
- Examples
350
- --------
351
- >>> from polars import col as c
352
- >>> df = pl.DataFrame(
353
- ... {
354
- ... "foo": [1, 2],
355
- ... "bar": [3, 4],
356
- ... }
357
- ... )
358
- >>> df.select(c.foo + c.bar)
359
- shape: (2, 1)
360
- ┌─────┐
361
- │ foo │
362
- │ --- │
363
- │ i64 │
364
- ╞═════╡
365
- │ 4 │
366
- │ 6 │
367
- └─────┘
368
- """
369
- # For autocomplete to work with IPython
370
- if name.startswith("__wrapped__"):
371
- return getattr(type(self), name)
372
-
373
- return _create_col(name)
374
-
375
- if not sys.version_info >= (3, 11):
376
-
377
- def __getstate__(self) -> Any:
378
- return self.__dict__
379
-
380
- def __setstate__(self, state: Any) -> None:
381
- self.__dict__ = state
382
-
383
-
384
- col: Col = Col()
@@ -1,121 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- import polars._reexport as pl
6
- from polars import functions as F
7
- from polars._utils.unstable import unstable
8
- from polars._utils.various import qualified_type_name
9
-
10
- if TYPE_CHECKING:
11
- from collections.abc import Mapping
12
-
13
- from polars import Expr
14
- from polars._typing import PolarsDataType
15
-
16
-
17
- @unstable()
18
- def dtype_of(col_or_expr: str | Expr) -> pl.DataTypeExpr:
19
- """
20
- Get a lazily evaluated :class:`DataType` of a column or expression.
21
-
22
- .. warning::
23
- This functionality is considered **unstable**. It may be changed
24
- at any point without it being considered a breaking change.
25
-
26
- Examples
27
- --------
28
- >>> def inspect(expr: pl.Expr) -> pl.Expr:
29
- ... def print_and_return(s: pl.Series) -> pl.Series:
30
- ... print(s)
31
- ... return s
32
- ...
33
- ... return expr.map_batches(
34
- ... print_and_return,
35
- ... # Clarify that the expression returns the same datatype as the input
36
- ... # datatype.
37
- ... return_dtype=pl.dtype_of(expr),
38
- ... )
39
- >>> df = pl.DataFrame(
40
- ... {
41
- ... "UserID": [1, 2, 3, 4, 5],
42
- ... "Name": ["Alice", "Bob", "Charlie", "Diana", "Ethan"],
43
- ... }
44
- ... )
45
- >>> df.select(inspect(pl.col("Name")))
46
- shape: (5,)
47
- Series: 'Name' [str]
48
- [
49
- "Alice"
50
- "Bob"
51
- "Charlie"
52
- "Diana"
53
- "Ethan"
54
- ]
55
- shape: (5, 1)
56
- ┌─────────┐
57
- │ Name │
58
- │ --- │
59
- │ str │
60
- ╞═════════╡
61
- │ Alice │
62
- │ Bob │
63
- │ Charlie │
64
- │ Diana │
65
- │ Ethan │
66
- └─────────┘
67
- """
68
- from polars._plr import PyDataTypeExpr
69
-
70
- e: Expr
71
- if isinstance(col_or_expr, str):
72
- e = F.col(col_or_expr)
73
- else:
74
- e = col_or_expr
75
-
76
- return pl.DataTypeExpr._from_pydatatype_expr(PyDataTypeExpr.of_expr(e._pyexpr))
77
-
78
-
79
- @unstable()
80
- def self_dtype() -> pl.DataTypeExpr:
81
- """
82
- Get the dtype of `self` in `map_elements` and `map_batches`.
83
-
84
- .. warning::
85
- This functionality is considered **unstable**. It may be changed
86
- at any point without it being considered a breaking change.
87
- """
88
- from polars._plr import PyDataTypeExpr
89
-
90
- return pl.DataTypeExpr._from_pydatatype_expr(PyDataTypeExpr.self_dtype())
91
-
92
-
93
- @unstable()
94
- def struct_with_fields(
95
- mapping: Mapping[str, PolarsDataType | pl.DataTypeExpr],
96
- ) -> pl.DataTypeExpr:
97
- """
98
- Create a new datatype expression that represents a Struct datatype.
99
-
100
- .. warning::
101
- This functionality is considered **unstable**. It may be changed
102
- at any point without it being considered a breaking change.
103
- """
104
- from polars._plr import PyDataTypeExpr
105
-
106
- def preprocess(dtype_expr: PolarsDataType | pl.DataTypeExpr) -> PyDataTypeExpr:
107
- if isinstance(dtype_expr, pl.DataType):
108
- return dtype_expr.to_dtype_expr()._pydatatype_expr
109
- if isinstance(dtype_expr, pl.DataTypeClass):
110
- return dtype_expr.to_dtype_expr()._pydatatype_expr
111
- elif isinstance(dtype_expr, pl.DataTypeExpr):
112
- return dtype_expr._pydatatype_expr
113
- else:
114
- msg = f"mapping item must be a datatype or datatype expression; found {qualified_type_name(dtype_expr)!r}"
115
- raise TypeError(msg)
116
-
117
- fields = [(name, preprocess(dtype_expr)) for (name, dtype_expr) in mapping.items()]
118
-
119
- return pl.DataTypeExpr._from_pydatatype_expr(
120
- PyDataTypeExpr.struct_with_fields(fields)
121
- )