polars-runtime-compat 1.34.0b3__cp39-abi3-win_amd64.whl → 1.34.0b5__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.

Files changed (204) hide show
  1. _polars_runtime_compat/_polars_runtime_compat.pyd +0 -0
  2. polars_runtime_compat-1.34.0b5.dist-info/METADATA +35 -0
  3. polars_runtime_compat-1.34.0b5.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 -103
  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.0b3.dist-info/METADATA +0 -190
  202. polars_runtime_compat-1.34.0b3.dist-info/RECORD +0 -203
  203. {polars_runtime_compat-1.34.0b3.dist-info → polars_runtime_compat-1.34.0b5.dist-info}/WHEEL +0 -0
  204. {polars_runtime_compat-1.34.0b3.dist-info → polars_runtime_compat-1.34.0b5.dist-info}/licenses/LICENSE +0 -0
polars/_utils/getitem.py DELETED
@@ -1,457 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from collections.abc import Sequence
4
- from typing import TYPE_CHECKING, Any, NoReturn, overload
5
-
6
- import polars._reexport as pl
7
- import polars.functions as F
8
- from polars._dependencies import _check_for_numpy
9
- from polars._dependencies import numpy as np
10
- from polars._utils.constants import U32_MAX
11
- from polars._utils.slice import PolarsSlice
12
- from polars._utils.various import qualified_type_name, range_to_slice
13
- from polars.datatypes.classes import (
14
- Boolean,
15
- Int8,
16
- Int16,
17
- Int32,
18
- Int64,
19
- String,
20
- UInt32,
21
- UInt64,
22
- )
23
- from polars.meta.index_type import get_index_type
24
-
25
- if TYPE_CHECKING:
26
- from collections.abc import Iterable
27
-
28
- from polars import DataFrame, Series
29
- from polars._typing import (
30
- MultiColSelector,
31
- MultiIndexSelector,
32
- SingleColSelector,
33
- SingleIndexSelector,
34
- )
35
-
36
- __all__ = [
37
- "get_df_item_by_key",
38
- "get_series_item_by_key",
39
- ]
40
-
41
-
42
- @overload
43
- def get_series_item_by_key(s: Series, key: SingleIndexSelector) -> Any: ...
44
-
45
-
46
- @overload
47
- def get_series_item_by_key(s: Series, key: MultiIndexSelector) -> Series: ...
48
-
49
-
50
- def get_series_item_by_key(
51
- s: Series, key: SingleIndexSelector | MultiIndexSelector
52
- ) -> Any | Series:
53
- """Select one or more elements from the Series."""
54
- if isinstance(key, int):
55
- return s._s.get_index_signed(key)
56
-
57
- elif isinstance(key, slice):
58
- return _select_elements_by_slice(s, key)
59
-
60
- elif isinstance(key, range):
61
- key = range_to_slice(key)
62
- return _select_elements_by_slice(s, key)
63
-
64
- elif isinstance(key, Sequence):
65
- if not key:
66
- return s.clear()
67
-
68
- first = key[0]
69
- if isinstance(first, bool):
70
- _raise_on_boolean_mask()
71
-
72
- try:
73
- indices = pl.Series("", key, dtype=Int64)
74
- except TypeError:
75
- msg = f"cannot select elements using Sequence with elements of type {qualified_type_name(first)!r}"
76
- raise TypeError(msg) from None
77
-
78
- indices = _convert_series_to_indices(indices, s.len())
79
- return _select_elements_by_index(s, indices)
80
-
81
- elif isinstance(key, pl.Series):
82
- indices = _convert_series_to_indices(key, s.len())
83
- return _select_elements_by_index(s, indices)
84
-
85
- elif _check_for_numpy(key) and isinstance(key, np.ndarray):
86
- indices = _convert_np_ndarray_to_indices(key, s.len())
87
- return _select_elements_by_index(s, indices)
88
-
89
- msg = f"cannot select elements using key of type {qualified_type_name(key)!r}: {key!r}"
90
- raise TypeError(msg)
91
-
92
-
93
- def _select_elements_by_slice(s: Series, key: slice) -> Series:
94
- return PolarsSlice(s).apply(key) # type: ignore[return-value]
95
-
96
-
97
- def _select_elements_by_index(s: Series, key: Series) -> Series:
98
- return s._from_pyseries(s._s.gather_with_series(key._s))
99
-
100
-
101
- # `str` overlaps with `Sequence[str]`
102
- # We can ignore this but we must keep this overload ordering
103
- @overload
104
- def get_df_item_by_key(
105
- df: DataFrame, key: tuple[SingleIndexSelector, SingleColSelector]
106
- ) -> Any: ...
107
-
108
-
109
- @overload
110
- def get_df_item_by_key( # type: ignore[overload-overlap]
111
- df: DataFrame, key: str | tuple[MultiIndexSelector, SingleColSelector]
112
- ) -> Series: ...
113
-
114
-
115
- @overload
116
- def get_df_item_by_key(
117
- df: DataFrame,
118
- key: (
119
- SingleIndexSelector
120
- | MultiIndexSelector
121
- | MultiColSelector
122
- | tuple[SingleIndexSelector, MultiColSelector]
123
- | tuple[MultiIndexSelector, MultiColSelector]
124
- ),
125
- ) -> DataFrame: ...
126
-
127
-
128
- def get_df_item_by_key(
129
- df: DataFrame,
130
- key: (
131
- SingleIndexSelector
132
- | SingleColSelector
133
- | MultiColSelector
134
- | MultiIndexSelector
135
- | tuple[SingleIndexSelector, SingleColSelector]
136
- | tuple[SingleIndexSelector, MultiColSelector]
137
- | tuple[MultiIndexSelector, SingleColSelector]
138
- | tuple[MultiIndexSelector, MultiColSelector]
139
- ),
140
- ) -> DataFrame | Series | Any:
141
- """Get part of the DataFrame as a new DataFrame, Series, or scalar."""
142
- # Two inputs, e.g. df[1, 2:5]
143
- if isinstance(key, tuple) and len(key) == 2:
144
- row_key, col_key = key
145
-
146
- # Support df[True, False] and df["a", "b"] as these are not ambiguous
147
- if isinstance(row_key, (bool, str)):
148
- return _select_columns(df, key) # type: ignore[arg-type]
149
-
150
- selection = _select_columns(df, col_key)
151
-
152
- if selection.is_empty():
153
- return selection
154
- elif isinstance(selection, pl.Series):
155
- return get_series_item_by_key(selection, row_key)
156
- else:
157
- return _select_rows(selection, row_key)
158
-
159
- # Single string input, e.g. df["a"]
160
- if isinstance(key, str):
161
- # This case is required because empty strings are otherwise treated
162
- # as an empty Sequence in `_select_rows`
163
- return df.get_column(key)
164
-
165
- # Single input - df[1] - or multiple inputs - df["a", "b", "c"]
166
- try:
167
- return _select_rows(df, key) # type: ignore[arg-type]
168
- except TypeError:
169
- return _select_columns(df, key)
170
-
171
-
172
- # `str` overlaps with `Sequence[str]`
173
- # We can ignore this but we must keep this overload ordering
174
- @overload
175
- def _select_columns(df: DataFrame, key: SingleColSelector) -> Series: ... # type: ignore[overload-overlap]
176
-
177
-
178
- @overload
179
- def _select_columns(df: DataFrame, key: MultiColSelector) -> DataFrame: ...
180
-
181
-
182
- def _select_columns(
183
- df: DataFrame, key: SingleColSelector | MultiColSelector
184
- ) -> DataFrame | Series:
185
- """Select one or more columns from the DataFrame."""
186
- if isinstance(key, int):
187
- return df.to_series(key)
188
-
189
- elif isinstance(key, str):
190
- return df.get_column(key)
191
-
192
- elif isinstance(key, slice):
193
- start, stop, step = key.start, key.stop, key.step
194
- # Fast path for common case: df[x, :]
195
- if start is None and stop is None and step is None:
196
- return df
197
- if isinstance(start, str):
198
- start = df.get_column_index(start)
199
- if isinstance(stop, str):
200
- stop = df.get_column_index(stop) + 1
201
- int_slice = slice(start, stop, step)
202
- rng = range(df.width)[int_slice]
203
- return _select_columns_by_index(df, rng)
204
-
205
- elif isinstance(key, range):
206
- return _select_columns_by_index(df, key)
207
-
208
- elif isinstance(key, Sequence):
209
- if not key:
210
- return df.__class__()
211
- first = key[0]
212
- if isinstance(first, bool):
213
- return _select_columns_by_mask(df, key) # type: ignore[arg-type]
214
- elif isinstance(first, int):
215
- return _select_columns_by_index(df, key) # type: ignore[arg-type]
216
- elif isinstance(first, str):
217
- return _select_columns_by_name(df, key) # type: ignore[arg-type]
218
- else:
219
- msg = f"cannot select columns using Sequence with elements of type {qualified_type_name(first)!r}"
220
- raise TypeError(msg)
221
-
222
- elif isinstance(key, pl.Series):
223
- if key.is_empty():
224
- return df.__class__()
225
- dtype = key.dtype
226
- if dtype == String:
227
- return _select_columns_by_name(df, key)
228
- elif dtype.is_integer():
229
- return _select_columns_by_index(df, key)
230
- elif dtype == Boolean:
231
- return _select_columns_by_mask(df, key)
232
- else:
233
- msg = f"cannot select columns using Series of type {dtype}"
234
- raise TypeError(msg)
235
-
236
- elif _check_for_numpy(key) and isinstance(key, np.ndarray):
237
- if key.ndim == 0:
238
- key = np.atleast_1d(key)
239
- elif key.ndim != 1:
240
- msg = "multi-dimensional NumPy arrays not supported as index"
241
- raise TypeError(msg)
242
-
243
- if len(key) == 0:
244
- return df.__class__()
245
-
246
- dtype_kind = key.dtype.kind
247
- if dtype_kind in ("i", "u"):
248
- return _select_columns_by_index(df, key)
249
- elif dtype_kind == "b":
250
- return _select_columns_by_mask(df, key)
251
- elif isinstance(key[0], str):
252
- return _select_columns_by_name(df, key)
253
- else:
254
- msg = f"cannot select columns using NumPy array of type {key.dtype}"
255
- raise TypeError(msg)
256
-
257
- msg = (
258
- f"cannot select columns using key of type {qualified_type_name(key)!r}: {key!r}"
259
- )
260
- raise TypeError(msg)
261
-
262
-
263
- def _select_columns_by_index(df: DataFrame, key: Iterable[int]) -> DataFrame:
264
- series = [df.to_series(i) for i in key]
265
- return df.__class__(series)
266
-
267
-
268
- def _select_columns_by_name(df: DataFrame, key: Iterable[str]) -> DataFrame:
269
- return df._from_pydf(df._df.select(list(key)))
270
-
271
-
272
- def _select_columns_by_mask(
273
- df: DataFrame, key: Sequence[bool] | Series | np.ndarray[Any, Any]
274
- ) -> DataFrame:
275
- if len(key) != df.width:
276
- msg = f"expected {df.width} values when selecting columns by boolean mask, got {len(key)}"
277
- raise ValueError(msg)
278
-
279
- indices = (i for i, val in enumerate(key) if val)
280
- return _select_columns_by_index(df, indices)
281
-
282
-
283
- @overload
284
- def _select_rows(df: DataFrame, key: SingleIndexSelector) -> Series: ...
285
-
286
-
287
- @overload
288
- def _select_rows(df: DataFrame, key: MultiIndexSelector) -> DataFrame: ...
289
-
290
-
291
- def _select_rows(
292
- df: DataFrame, key: SingleIndexSelector | MultiIndexSelector
293
- ) -> DataFrame | Series:
294
- """Select one or more rows from the DataFrame."""
295
- if isinstance(key, int):
296
- num_rows = df.height
297
- if (key >= num_rows) or (key < -num_rows):
298
- msg = f"index {key} is out of bounds for DataFrame of height {num_rows}"
299
- raise IndexError(msg)
300
- return df.slice(key, 1)
301
-
302
- if isinstance(key, slice):
303
- return _select_rows_by_slice(df, key)
304
-
305
- elif isinstance(key, range):
306
- key = range_to_slice(key)
307
- return _select_rows_by_slice(df, key)
308
-
309
- elif isinstance(key, Sequence):
310
- if not key:
311
- return df.clear()
312
- if isinstance(key[0], bool):
313
- _raise_on_boolean_mask()
314
- s = pl.Series("", key, dtype=Int64)
315
- indices = _convert_series_to_indices(s, df.height)
316
- return _select_rows_by_index(df, indices)
317
-
318
- elif isinstance(key, pl.Series):
319
- indices = _convert_series_to_indices(key, df.height)
320
- return _select_rows_by_index(df, indices)
321
-
322
- elif _check_for_numpy(key) and isinstance(key, np.ndarray):
323
- indices = _convert_np_ndarray_to_indices(key, df.height)
324
- return _select_rows_by_index(df, indices)
325
-
326
- else:
327
- msg = f"cannot select rows using key of type {qualified_type_name(key)!r}: {key!r}"
328
- raise TypeError(msg)
329
-
330
-
331
- def _select_rows_by_slice(df: DataFrame, key: slice) -> DataFrame:
332
- return PolarsSlice(df).apply(key) # type: ignore[return-value]
333
-
334
-
335
- def _select_rows_by_index(df: DataFrame, key: Series) -> DataFrame:
336
- return df._from_pydf(df._df.gather_with_series(key._s))
337
-
338
-
339
- # UTILS
340
-
341
-
342
- def _convert_series_to_indices(s: Series, size: int) -> Series:
343
- """Convert a Series to indices, taking into account negative values."""
344
- # Unsigned or signed Series (ordered from fastest to slowest).
345
- # - pl.UInt32 (polars) or pl.UInt64 (polars_u64_idx) Series indexes.
346
- # - Other unsigned Series indexes are converted to pl.UInt32 (polars)
347
- # or pl.UInt64 (polars_u64_idx).
348
- # - Signed Series indexes are converted pl.UInt32 (polars) or
349
- # pl.UInt64 (polars_u64_idx) after negative indexes are converted
350
- # to absolute indexes.
351
-
352
- # pl.UInt32 (polars) or pl.UInt64 (polars_u64_idx).
353
- idx_type = get_index_type()
354
-
355
- if s.dtype == idx_type:
356
- return s
357
-
358
- if not s.dtype.is_integer():
359
- if s.dtype == Boolean:
360
- _raise_on_boolean_mask()
361
- else:
362
- msg = f"cannot treat Series of type {s.dtype} as indices"
363
- raise TypeError(msg)
364
-
365
- if s.len() == 0:
366
- return pl.Series(s.name, [], dtype=idx_type)
367
-
368
- if idx_type == UInt32:
369
- if s.dtype in {Int64, UInt64} and s.max() >= U32_MAX: # type: ignore[operator]
370
- msg = "index positions should be smaller than 2^32"
371
- raise ValueError(msg)
372
- if s.dtype == Int64 and s.min() < -U32_MAX: # type: ignore[operator]
373
- msg = "index positions should be greater than or equal to -2^32"
374
- raise ValueError(msg)
375
-
376
- if s.dtype.is_signed_integer():
377
- if s.min() < 0: # type: ignore[operator]
378
- if idx_type == UInt32:
379
- idxs = s.cast(Int32) if s.dtype in {Int8, Int16} else s
380
- else:
381
- idxs = s.cast(Int64) if s.dtype in {Int8, Int16, Int32} else s
382
-
383
- # Update negative indexes to absolute indexes.
384
- return (
385
- idxs.to_frame()
386
- .select(
387
- F.when(F.col(idxs.name) < 0)
388
- .then(size + F.col(idxs.name))
389
- .otherwise(F.col(idxs.name))
390
- .cast(idx_type)
391
- )
392
- .to_series(0)
393
- )
394
-
395
- return s.cast(idx_type)
396
-
397
-
398
- def _convert_np_ndarray_to_indices(arr: np.ndarray[Any, Any], size: int) -> Series:
399
- """Convert a NumPy ndarray to indices, taking into account negative values."""
400
- # Unsigned or signed Numpy array (ordered from fastest to slowest).
401
- # - np.uint32 (polars) or np.uint64 (polars_u64_idx) numpy array
402
- # indexes.
403
- # - Other unsigned numpy array indexes are converted to pl.UInt32
404
- # (polars) or pl.UInt64 (polars_u64_idx).
405
- # - Signed numpy array indexes are converted pl.UInt32 (polars) or
406
- # pl.UInt64 (polars_u64_idx) after negative indexes are converted
407
- # to absolute indexes.
408
- if arr.ndim == 0:
409
- arr = np.atleast_1d(arr)
410
- if arr.ndim != 1:
411
- msg = "only 1D NumPy arrays can be treated as indices"
412
- raise TypeError(msg)
413
-
414
- idx_type = get_index_type()
415
-
416
- if len(arr) == 0:
417
- return pl.Series("", [], dtype=idx_type)
418
-
419
- # Numpy array with signed or unsigned integers.
420
- if arr.dtype.kind not in ("i", "u"):
421
- if arr.dtype.kind == "b":
422
- _raise_on_boolean_mask()
423
- else:
424
- msg = f"cannot treat NumPy array of type {arr.dtype} as indices"
425
- raise TypeError(msg)
426
-
427
- if idx_type == UInt32:
428
- if arr.dtype in {np.int64, np.uint64} and arr.max() >= U32_MAX:
429
- msg = "index positions should be smaller than 2^32"
430
- raise ValueError(msg)
431
- if arr.dtype == np.int64 and arr.min() < -U32_MAX:
432
- msg = "index positions should be greater than or equal to -2^32"
433
- raise ValueError(msg)
434
-
435
- if arr.dtype.kind == "i" and arr.min() < 0:
436
- if idx_type == UInt32:
437
- if arr.dtype in (np.int8, np.int16):
438
- arr = arr.astype(np.int32)
439
- else:
440
- if arr.dtype in (np.int8, np.int16, np.int32):
441
- arr = arr.astype(np.int64)
442
-
443
- # Update negative indexes to absolute indexes.
444
- arr = np.where(arr < 0, size + arr, arr)
445
-
446
- # numpy conversion is much faster
447
- arr = arr.astype(np.uint32) if idx_type == UInt32 else arr.astype(np.uint64)
448
-
449
- return pl.Series("", arr, dtype=idx_type)
450
-
451
-
452
- def _raise_on_boolean_mask() -> NoReturn:
453
- msg = (
454
- "selecting rows by passing a boolean mask to `__getitem__` is not supported"
455
- "\n\nHint: Use the `filter` method instead."
456
- )
457
- raise TypeError(msg)
polars/_utils/logging.py DELETED
@@ -1,11 +0,0 @@
1
- import os
2
- import sys
3
- from typing import Any
4
-
5
-
6
- def verbose() -> bool:
7
- return os.getenv("POLARS_VERBOSE") == "1"
8
-
9
-
10
- def eprint(*a: Any, **kw: Any) -> None:
11
- return print(*a, file=sys.stderr, **kw)