polars-df 0.13.0-x64-mingw-ucrt
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.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +208 -0
- data/Cargo.lock +2556 -0
- data/Cargo.toml +6 -0
- data/LICENSE-THIRD-PARTY.txt +39278 -0
- data/LICENSE.txt +20 -0
- data/README.md +437 -0
- data/lib/polars/3.1/polars.so +0 -0
- data/lib/polars/3.2/polars.so +0 -0
- data/lib/polars/3.3/polars.so +0 -0
- data/lib/polars/array_expr.rb +537 -0
- data/lib/polars/array_name_space.rb +423 -0
- data/lib/polars/batched_csv_reader.rb +104 -0
- data/lib/polars/binary_expr.rb +77 -0
- data/lib/polars/binary_name_space.rb +66 -0
- data/lib/polars/cat_expr.rb +36 -0
- data/lib/polars/cat_name_space.rb +88 -0
- data/lib/polars/config.rb +530 -0
- data/lib/polars/convert.rb +98 -0
- data/lib/polars/data_frame.rb +5191 -0
- data/lib/polars/data_types.rb +466 -0
- data/lib/polars/date_time_expr.rb +1397 -0
- data/lib/polars/date_time_name_space.rb +1287 -0
- data/lib/polars/dynamic_group_by.rb +52 -0
- data/lib/polars/exceptions.rb +38 -0
- data/lib/polars/expr.rb +7256 -0
- data/lib/polars/expr_dispatch.rb +22 -0
- data/lib/polars/functions/aggregation/horizontal.rb +246 -0
- data/lib/polars/functions/aggregation/vertical.rb +282 -0
- data/lib/polars/functions/as_datatype.rb +271 -0
- data/lib/polars/functions/col.rb +47 -0
- data/lib/polars/functions/eager.rb +182 -0
- data/lib/polars/functions/lazy.rb +1329 -0
- data/lib/polars/functions/len.rb +49 -0
- data/lib/polars/functions/lit.rb +35 -0
- data/lib/polars/functions/random.rb +16 -0
- data/lib/polars/functions/range/date_range.rb +136 -0
- data/lib/polars/functions/range/datetime_range.rb +149 -0
- data/lib/polars/functions/range/int_range.rb +51 -0
- data/lib/polars/functions/range/time_range.rb +141 -0
- data/lib/polars/functions/repeat.rb +144 -0
- data/lib/polars/functions/whenthen.rb +96 -0
- data/lib/polars/functions.rb +57 -0
- data/lib/polars/group_by.rb +613 -0
- data/lib/polars/io/avro.rb +24 -0
- data/lib/polars/io/csv.rb +696 -0
- data/lib/polars/io/database.rb +73 -0
- data/lib/polars/io/ipc.rb +275 -0
- data/lib/polars/io/json.rb +29 -0
- data/lib/polars/io/ndjson.rb +80 -0
- data/lib/polars/io/parquet.rb +233 -0
- data/lib/polars/lazy_frame.rb +2708 -0
- data/lib/polars/lazy_group_by.rb +181 -0
- data/lib/polars/list_expr.rb +791 -0
- data/lib/polars/list_name_space.rb +449 -0
- data/lib/polars/meta_expr.rb +222 -0
- data/lib/polars/name_expr.rb +198 -0
- data/lib/polars/plot.rb +109 -0
- data/lib/polars/rolling_group_by.rb +35 -0
- data/lib/polars/series.rb +4444 -0
- data/lib/polars/slice.rb +104 -0
- data/lib/polars/sql_context.rb +194 -0
- data/lib/polars/string_cache.rb +75 -0
- data/lib/polars/string_expr.rb +1495 -0
- data/lib/polars/string_name_space.rb +811 -0
- data/lib/polars/struct_expr.rb +98 -0
- data/lib/polars/struct_name_space.rb +96 -0
- data/lib/polars/testing.rb +507 -0
- data/lib/polars/utils/constants.rb +9 -0
- data/lib/polars/utils/convert.rb +97 -0
- data/lib/polars/utils/parse.rb +89 -0
- data/lib/polars/utils/various.rb +76 -0
- data/lib/polars/utils/wrap.rb +19 -0
- data/lib/polars/utils.rb +130 -0
- data/lib/polars/version.rb +4 -0
- data/lib/polars/whenthen.rb +83 -0
- data/lib/polars-df.rb +1 -0
- data/lib/polars.rb +91 -0
- metadata +138 -0
@@ -0,0 +1,449 @@
|
|
1
|
+
module Polars
|
2
|
+
# Series.list namespace.
|
3
|
+
class ListNameSpace
|
4
|
+
include ExprDispatch
|
5
|
+
|
6
|
+
self._accessor = "list"
|
7
|
+
|
8
|
+
# @private
|
9
|
+
def initialize(series)
|
10
|
+
self._s = series._s
|
11
|
+
end
|
12
|
+
|
13
|
+
# Evaluate whether all boolean values in a list are true.
|
14
|
+
#
|
15
|
+
# @return [Series]
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# s = Polars::Series.new(
|
19
|
+
# [[true, true], [false, true], [false, false], [nil], [], nil],
|
20
|
+
# dtype: Polars::List.new(Polars::Boolean)
|
21
|
+
# )
|
22
|
+
# s.list.all
|
23
|
+
# # =>
|
24
|
+
# # shape: (6,)
|
25
|
+
# # Series: '' [bool]
|
26
|
+
# # [
|
27
|
+
# # true
|
28
|
+
# # false
|
29
|
+
# # false
|
30
|
+
# # true
|
31
|
+
# # true
|
32
|
+
# # null
|
33
|
+
# # ]
|
34
|
+
def all
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
# Evaluate whether any boolean value in a list is true.
|
39
|
+
#
|
40
|
+
# @return [Series]
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# s = Polars::Series.new(
|
44
|
+
# [[true, true], [false, true], [false, false], [nil], [], nil],
|
45
|
+
# dtype: Polars::List.new(Polars::Boolean)
|
46
|
+
# )
|
47
|
+
# s.list.any
|
48
|
+
# # =>
|
49
|
+
# # shape: (6,)
|
50
|
+
# # Series: '' [bool]
|
51
|
+
# # [
|
52
|
+
# # true
|
53
|
+
# # true
|
54
|
+
# # false
|
55
|
+
# # false
|
56
|
+
# # false
|
57
|
+
# # null
|
58
|
+
# # ]
|
59
|
+
def any
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
# Get the length of the arrays as UInt32.
|
64
|
+
#
|
65
|
+
# @return [Series]
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# s = Polars::Series.new([[1, 2, 3], [5]])
|
69
|
+
# s.list.lengths
|
70
|
+
# # =>
|
71
|
+
# # shape: (2,)
|
72
|
+
# # Series: '' [u32]
|
73
|
+
# # [
|
74
|
+
# # 3
|
75
|
+
# # 1
|
76
|
+
# # ]
|
77
|
+
def lengths
|
78
|
+
super
|
79
|
+
end
|
80
|
+
|
81
|
+
# Drop all null values in the list.
|
82
|
+
#
|
83
|
+
# The original order of the remaining elements is preserved.
|
84
|
+
#
|
85
|
+
# @return [Series]
|
86
|
+
#
|
87
|
+
# @example
|
88
|
+
# s = Polars::Series.new("values", [[nil, 1, nil, 2], [nil], [3, 4]])
|
89
|
+
# s.list.drop_nulls
|
90
|
+
# # =>
|
91
|
+
# # shape: (3,)
|
92
|
+
# # Series: 'values' [list[i64]]
|
93
|
+
# # [
|
94
|
+
# # [1, 2]
|
95
|
+
# # []
|
96
|
+
# # [3, 4]
|
97
|
+
# # ]
|
98
|
+
def drop_nulls
|
99
|
+
super
|
100
|
+
end
|
101
|
+
|
102
|
+
# Sample from this list.
|
103
|
+
#
|
104
|
+
# @param n [Integer]
|
105
|
+
# Number of items to return. Cannot be used with `fraction`. Defaults to 1 if
|
106
|
+
# `fraction` is nil.
|
107
|
+
# @param fraction [Float]
|
108
|
+
# Fraction of items to return. Cannot be used with `n`.
|
109
|
+
# @param with_replacement [Boolean]
|
110
|
+
# Allow values to be sampled more than once.
|
111
|
+
# @param shuffle [Boolean]
|
112
|
+
# Shuffle the order of sampled data points.
|
113
|
+
# @param seed [Integer]
|
114
|
+
# Seed for the random number generator. If set to nil (default), a
|
115
|
+
# random seed is generated for each sample operation.
|
116
|
+
#
|
117
|
+
# @return [Series]
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# s = Polars::Series.new("values", [[1, 2, 3], [4, 5]])
|
121
|
+
# s.list.sample(n: Polars::Series.new("n", [2, 1]), seed: 1)
|
122
|
+
# # =>
|
123
|
+
# # shape: (2,)
|
124
|
+
# # Series: 'values' [list[i64]]
|
125
|
+
# # [
|
126
|
+
# # [2, 1]
|
127
|
+
# # [5]
|
128
|
+
# # ]
|
129
|
+
def sample(n: nil, fraction: nil, with_replacement: false, shuffle: false, seed: nil)
|
130
|
+
super
|
131
|
+
end
|
132
|
+
|
133
|
+
# Sum all the arrays in the list.
|
134
|
+
#
|
135
|
+
# @return [Series]
|
136
|
+
def sum
|
137
|
+
super
|
138
|
+
end
|
139
|
+
|
140
|
+
# Compute the max value of the arrays in the list.
|
141
|
+
#
|
142
|
+
# @return [Series]
|
143
|
+
def max
|
144
|
+
super
|
145
|
+
end
|
146
|
+
|
147
|
+
# Compute the min value of the arrays in the list.
|
148
|
+
#
|
149
|
+
# @return [Series]
|
150
|
+
def min
|
151
|
+
super
|
152
|
+
end
|
153
|
+
|
154
|
+
# Compute the mean value of the arrays in the list.
|
155
|
+
#
|
156
|
+
# @return [Series]
|
157
|
+
def mean
|
158
|
+
super
|
159
|
+
end
|
160
|
+
|
161
|
+
# Sort the arrays in the list.
|
162
|
+
#
|
163
|
+
# @return [Series]
|
164
|
+
def sort(reverse: false)
|
165
|
+
super
|
166
|
+
end
|
167
|
+
|
168
|
+
# Reverse the arrays in the list.
|
169
|
+
#
|
170
|
+
# @return [Series]
|
171
|
+
def reverse
|
172
|
+
super
|
173
|
+
end
|
174
|
+
|
175
|
+
# Get the unique/distinct values in the list.
|
176
|
+
#
|
177
|
+
# @return [Series]
|
178
|
+
def unique
|
179
|
+
super
|
180
|
+
end
|
181
|
+
|
182
|
+
# Concat the arrays in a Series dtype List in linear time.
|
183
|
+
#
|
184
|
+
# @param other [Object]
|
185
|
+
# Columns to concat into a List Series
|
186
|
+
#
|
187
|
+
# @return [Series]
|
188
|
+
def concat(other)
|
189
|
+
super
|
190
|
+
end
|
191
|
+
|
192
|
+
# Get the value by index in the sublists.
|
193
|
+
#
|
194
|
+
# So index `0` would return the first item of every sublist
|
195
|
+
# and index `-1` would return the last item of every sublist
|
196
|
+
# if an index is out of bounds, it will return a `None`.
|
197
|
+
#
|
198
|
+
# @param index [Integer]
|
199
|
+
# Index to return per sublist
|
200
|
+
# @param null_on_oob [Boolean]
|
201
|
+
# Behavior if an index is out of bounds:
|
202
|
+
# true -> set as null
|
203
|
+
# false -> raise an error
|
204
|
+
#
|
205
|
+
# @return [Series]
|
206
|
+
def get(index, null_on_oob: false)
|
207
|
+
super
|
208
|
+
end
|
209
|
+
|
210
|
+
# Get the value by index in the sublists.
|
211
|
+
#
|
212
|
+
# @return [Series]
|
213
|
+
def [](item)
|
214
|
+
get(item)
|
215
|
+
end
|
216
|
+
|
217
|
+
# Join all string items in a sublist and place a separator between them.
|
218
|
+
#
|
219
|
+
# This errors if inner type of list `!= Utf8`.
|
220
|
+
#
|
221
|
+
# @param separator [String]
|
222
|
+
# string to separate the items with
|
223
|
+
#
|
224
|
+
# @return [Series]
|
225
|
+
#
|
226
|
+
# @example
|
227
|
+
# s = Polars::Series.new([["foo", "bar"], ["hello", "world"]])
|
228
|
+
# s.list.join("-")
|
229
|
+
# # =>
|
230
|
+
# # shape: (2,)
|
231
|
+
# # Series: '' [str]
|
232
|
+
# # [
|
233
|
+
# # "foo-bar"
|
234
|
+
# # "hello-world"
|
235
|
+
# # ]
|
236
|
+
def join(separator)
|
237
|
+
super
|
238
|
+
end
|
239
|
+
|
240
|
+
# Get the first value of the sublists.
|
241
|
+
#
|
242
|
+
# @return [Series]
|
243
|
+
def first
|
244
|
+
super
|
245
|
+
end
|
246
|
+
|
247
|
+
# Get the last value of the sublists.
|
248
|
+
#
|
249
|
+
# @return [Series]
|
250
|
+
def last
|
251
|
+
super
|
252
|
+
end
|
253
|
+
|
254
|
+
# Check if sublists contain the given item.
|
255
|
+
#
|
256
|
+
# @param item [Object]
|
257
|
+
# Item that will be checked for membership.
|
258
|
+
#
|
259
|
+
# @return [Series]
|
260
|
+
def contains(item)
|
261
|
+
super
|
262
|
+
end
|
263
|
+
|
264
|
+
# Retrieve the index of the minimal value in every sublist.
|
265
|
+
#
|
266
|
+
# @return [Series]
|
267
|
+
def arg_min
|
268
|
+
super
|
269
|
+
end
|
270
|
+
|
271
|
+
# Retrieve the index of the maximum value in every sublist.
|
272
|
+
#
|
273
|
+
# @return [Series]
|
274
|
+
def arg_max
|
275
|
+
super
|
276
|
+
end
|
277
|
+
|
278
|
+
# Calculate the n-th discrete difference of every sublist.
|
279
|
+
#
|
280
|
+
# @param n [Integer]
|
281
|
+
# Number of slots to shift.
|
282
|
+
# @param null_behavior ["ignore", "drop"]
|
283
|
+
# How to handle null values.
|
284
|
+
#
|
285
|
+
# @return [Series]
|
286
|
+
#
|
287
|
+
# @example
|
288
|
+
# s = Polars::Series.new("a", [[1, 2, 3, 4], [10, 2, 1]])
|
289
|
+
# s.list.diff
|
290
|
+
# # =>
|
291
|
+
# # shape: (2,)
|
292
|
+
# # Series: 'a' [list[i64]]
|
293
|
+
# # [
|
294
|
+
# # [null, 1, … 1]
|
295
|
+
# # [null, -8, -1]
|
296
|
+
# # ]
|
297
|
+
def diff(n: 1, null_behavior: "ignore")
|
298
|
+
super
|
299
|
+
end
|
300
|
+
|
301
|
+
# Shift values by the given period.
|
302
|
+
#
|
303
|
+
# @param periods [Integer]
|
304
|
+
# Number of places to shift (may be negative).
|
305
|
+
#
|
306
|
+
# @return [Series]
|
307
|
+
#
|
308
|
+
# @example
|
309
|
+
# s = Polars::Series.new("a", [[1, 2, 3, 4], [10, 2, 1]])
|
310
|
+
# s.list.shift
|
311
|
+
# # =>
|
312
|
+
# # shape: (2,)
|
313
|
+
# # Series: 'a' [list[i64]]
|
314
|
+
# # [
|
315
|
+
# # [null, 1, … 3]
|
316
|
+
# # [null, 10, 2]
|
317
|
+
# # ]
|
318
|
+
def shift(periods = 1)
|
319
|
+
super
|
320
|
+
end
|
321
|
+
|
322
|
+
# Slice every sublist.
|
323
|
+
#
|
324
|
+
# @param offset [Integer]
|
325
|
+
# Start index. Negative indexing is supported.
|
326
|
+
# @param length [Integer]
|
327
|
+
# Length of the slice. If set to `nil` (default), the slice is taken to the
|
328
|
+
# end of the list.
|
329
|
+
#
|
330
|
+
# @return [Series]
|
331
|
+
#
|
332
|
+
# @example
|
333
|
+
# s = Polars::Series.new("a", [[1, 2, 3, 4], [10, 2, 1]])
|
334
|
+
# s.list.slice(1, 2)
|
335
|
+
# # =>
|
336
|
+
# # shape: (2,)
|
337
|
+
# # Series: 'a' [list[i64]]
|
338
|
+
# # [
|
339
|
+
# # [2, 3]
|
340
|
+
# # [2, 1]
|
341
|
+
# # ]
|
342
|
+
def slice(offset, length = nil)
|
343
|
+
super
|
344
|
+
end
|
345
|
+
|
346
|
+
# Slice the first `n` values of every sublist.
|
347
|
+
#
|
348
|
+
# @param n [Integer]
|
349
|
+
# Number of values to return for each sublist.
|
350
|
+
#
|
351
|
+
# @return [Series]
|
352
|
+
#
|
353
|
+
# @example
|
354
|
+
# s = Polars::Series.new("a", [[1, 2, 3, 4], [10, 2, 1]])
|
355
|
+
# s.list.head(2)
|
356
|
+
# # =>
|
357
|
+
# # shape: (2,)
|
358
|
+
# # Series: 'a' [list[i64]]
|
359
|
+
# # [
|
360
|
+
# # [1, 2]
|
361
|
+
# # [10, 2]
|
362
|
+
# # ]
|
363
|
+
def head(n = 5)
|
364
|
+
super
|
365
|
+
end
|
366
|
+
|
367
|
+
# Slice the last `n` values of every sublist.
|
368
|
+
#
|
369
|
+
# @param n [Integer]
|
370
|
+
# Number of values to return for each sublist.
|
371
|
+
#
|
372
|
+
# @return [Series]
|
373
|
+
#
|
374
|
+
# @example
|
375
|
+
# s = Polars::Series.new("a", [[1, 2, 3, 4], [10, 2, 1]])
|
376
|
+
# s.list.tail(2)
|
377
|
+
# # =>
|
378
|
+
# # shape: (2,)
|
379
|
+
# # Series: 'a' [list[i64]]
|
380
|
+
# # [
|
381
|
+
# # [3, 4]
|
382
|
+
# # [2, 1]
|
383
|
+
# # ]
|
384
|
+
def tail(n = 5)
|
385
|
+
super
|
386
|
+
end
|
387
|
+
|
388
|
+
# Convert the series of type `List` to a series of type `Struct`.
|
389
|
+
#
|
390
|
+
# @param n_field_strategy ["first_non_null", "max_width"]
|
391
|
+
# Strategy to determine the number of fields of the struct.
|
392
|
+
# @param name_generator [Object]
|
393
|
+
# A custom function that can be used to generate the field names.
|
394
|
+
# Default field names are `field_0, field_1 .. field_n`
|
395
|
+
#
|
396
|
+
# @return [Series]
|
397
|
+
#
|
398
|
+
# @example
|
399
|
+
# df = Polars::DataFrame.new({"a" => [[1, 2, 3], [1, 2]]})
|
400
|
+
# df.select([Polars.col("a").list.to_struct])
|
401
|
+
# # =>
|
402
|
+
# # shape: (2, 1)
|
403
|
+
# # ┌────────────┐
|
404
|
+
# # │ a │
|
405
|
+
# # │ --- │
|
406
|
+
# # │ struct[3] │
|
407
|
+
# # ╞════════════╡
|
408
|
+
# # │ {1,2,3} │
|
409
|
+
# # │ {1,2,null} │
|
410
|
+
# # └────────────┘
|
411
|
+
def to_struct(n_field_strategy: "first_non_null", name_generator: nil)
|
412
|
+
super
|
413
|
+
end
|
414
|
+
|
415
|
+
# Run any polars expression against the lists' elements.
|
416
|
+
#
|
417
|
+
# @param expr [Expr]
|
418
|
+
# Expression to run. Note that you can select an element with `Polars.first`, or
|
419
|
+
# `Polars.col`
|
420
|
+
# @param parallel [Boolean]
|
421
|
+
# Run all expression parallel. Don't activate this blindly.
|
422
|
+
# Parallelism is worth it if there is enough work to do per thread.
|
423
|
+
#
|
424
|
+
# This likely should not be use in the group by context, because we already
|
425
|
+
# parallel execution per group
|
426
|
+
#
|
427
|
+
# @return [Series]
|
428
|
+
#
|
429
|
+
# @example
|
430
|
+
# df = Polars::DataFrame.new({"a" => [1, 8, 3], "b" => [4, 5, 2]})
|
431
|
+
# df.with_column(
|
432
|
+
# Polars.concat_list(["a", "b"]).list.eval(Polars.element.rank).alias("rank")
|
433
|
+
# )
|
434
|
+
# # =>
|
435
|
+
# # shape: (3, 3)
|
436
|
+
# # ┌─────┬─────┬────────────┐
|
437
|
+
# # │ a ┆ b ┆ rank │
|
438
|
+
# # │ --- ┆ --- ┆ --- │
|
439
|
+
# # │ i64 ┆ i64 ┆ list[f64] │
|
440
|
+
# # ╞═════╪═════╪════════════╡
|
441
|
+
# # │ 1 ┆ 4 ┆ [1.0, 2.0] │
|
442
|
+
# # │ 8 ┆ 5 ┆ [2.0, 1.0] │
|
443
|
+
# # │ 3 ┆ 2 ┆ [2.0, 1.0] │
|
444
|
+
# # └─────┴─────┴────────────┘
|
445
|
+
def eval(expr, parallel: false)
|
446
|
+
super
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
module Polars
|
2
|
+
# Namespace for expressions on a meta level.
|
3
|
+
class MetaExpr
|
4
|
+
# @private
|
5
|
+
attr_accessor :_rbexpr
|
6
|
+
|
7
|
+
# @private
|
8
|
+
def initialize(expr)
|
9
|
+
self._rbexpr = expr._rbexpr
|
10
|
+
end
|
11
|
+
|
12
|
+
# Equal.
|
13
|
+
#
|
14
|
+
# @return [Boolean]
|
15
|
+
def ==(other)
|
16
|
+
_rbexpr.meta_eq(other._rbexpr)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Not equal.
|
20
|
+
#
|
21
|
+
# @return [Boolean]
|
22
|
+
def !=(other)
|
23
|
+
!(self == other)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Indicate if this expression is the same as another expression.
|
27
|
+
#
|
28
|
+
# @return [Boolean]
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# foo_bar = Polars.col("foo").alias("bar")
|
32
|
+
# foo = Polars.col("foo")
|
33
|
+
# foo_bar.meta.eq(foo)
|
34
|
+
# # => false
|
35
|
+
# foo_bar2 = Polars.col("foo").alias("bar")
|
36
|
+
# foo_bar.meta.eq(foo_bar2)
|
37
|
+
# # => true
|
38
|
+
def eq(other)
|
39
|
+
_rbexpr.meta_eq(other._rbexpr)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Indicate if this expression is NOT the same as another expression.
|
43
|
+
#
|
44
|
+
# @return [Boolean]
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# foo_bar = Polars.col("foo").alias("bar")
|
48
|
+
# foo = Polars.col("foo")
|
49
|
+
# foo_bar.meta.ne(foo)
|
50
|
+
# # => true
|
51
|
+
# foo_bar2 = Polars.col("foo").alias("bar")
|
52
|
+
# foo_bar.meta.ne(foo_bar2)
|
53
|
+
# # => false
|
54
|
+
def ne(other)
|
55
|
+
!eq(other)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Indicate if this expression expands into multiple expressions.
|
59
|
+
#
|
60
|
+
# @return [Boolean]
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# e = Polars.col(["a", "b"]).alias("bar")
|
64
|
+
# e.meta.has_multiple_outputs
|
65
|
+
# # => true
|
66
|
+
def has_multiple_outputs
|
67
|
+
_rbexpr.meta_has_multiple_outputs
|
68
|
+
end
|
69
|
+
|
70
|
+
# Indicate if this expression is a basic (non-regex) unaliased column.
|
71
|
+
#
|
72
|
+
# @return [Boolean]
|
73
|
+
#
|
74
|
+
# @example
|
75
|
+
# e = Polars.col("foo")
|
76
|
+
# e.meta.is_column
|
77
|
+
# # => true
|
78
|
+
# e = Polars.col("foo") * Polars.col("bar")
|
79
|
+
# e.meta.is_column
|
80
|
+
# # => false
|
81
|
+
# e = Polars.col("^col.*\d+$")
|
82
|
+
# e.meta.is_column
|
83
|
+
# # => false
|
84
|
+
def is_column
|
85
|
+
_rbexpr.meta_is_column
|
86
|
+
end
|
87
|
+
|
88
|
+
# Indicate if this expression expands to columns that match a regex pattern.
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# e = Polars.col("^.*$").alias("bar")
|
94
|
+
# e.meta.is_regex_projection
|
95
|
+
# # => true
|
96
|
+
def is_regex_projection
|
97
|
+
_rbexpr.meta_is_regex_projection
|
98
|
+
end
|
99
|
+
|
100
|
+
# Get the column name that this expression would produce.
|
101
|
+
#
|
102
|
+
# @return [String]
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# e = Polars.col("foo") * Polars.col("bar")
|
106
|
+
# e.meta.output_name
|
107
|
+
# # => "foo"
|
108
|
+
# e_filter = Polars.col("foo").filter(Polars.col("bar") == 13)
|
109
|
+
# e_filter.meta.output_name
|
110
|
+
# # => "foo"
|
111
|
+
# e_sum_over = Polars.sum("foo").over("groups")
|
112
|
+
# e_sum_over.meta.output_name
|
113
|
+
# # => "foo"
|
114
|
+
# e_sum_slice = Polars.sum("foo").slice(Polars.len - 10, Polars.col("bar"))
|
115
|
+
# e_sum_slice.meta.output_name
|
116
|
+
# # => "foo"
|
117
|
+
# Polars.len.meta.output_name
|
118
|
+
# # => "len"
|
119
|
+
def output_name
|
120
|
+
_rbexpr.meta_output_name
|
121
|
+
end
|
122
|
+
|
123
|
+
# Pop the latest expression and return the input(s) of the popped expression.
|
124
|
+
#
|
125
|
+
# @return [Array]
|
126
|
+
#
|
127
|
+
# @example
|
128
|
+
# e = Polars.col("foo").alias("bar")
|
129
|
+
# first = e.meta.pop[0]
|
130
|
+
# _ = first.meta == Polars.col("foo")
|
131
|
+
# # => true
|
132
|
+
# _ = first.meta == Polars.col("bar")
|
133
|
+
# # => false
|
134
|
+
def pop
|
135
|
+
_rbexpr.meta_pop.map { |e| Utils.wrap_expr(e) }
|
136
|
+
end
|
137
|
+
|
138
|
+
# Get a list with the root column name.
|
139
|
+
#
|
140
|
+
# @return [Array]
|
141
|
+
#
|
142
|
+
# @example
|
143
|
+
# e = Polars.col("foo") * Polars.col("bar")
|
144
|
+
# e.meta.root_names
|
145
|
+
# # => ["foo", "bar"]
|
146
|
+
# e_filter = Polars.col("foo").filter(Polars.col("bar") == 13)
|
147
|
+
# e_filter.meta.root_names
|
148
|
+
# # => ["foo", "bar"]
|
149
|
+
# e_sum_over = Polars.sum("foo").over("groups")
|
150
|
+
# e_sum_over.meta.root_names
|
151
|
+
# # => ["foo", "groups"]
|
152
|
+
# e_sum_slice = Polars.sum("foo").slice(Polars.len - 10, Polars.col("bar"))
|
153
|
+
# e_sum_slice.meta.root_names
|
154
|
+
# # => ["foo", "bar"]
|
155
|
+
def root_names
|
156
|
+
_rbexpr.meta_roots
|
157
|
+
end
|
158
|
+
|
159
|
+
# Undo any renaming operation like `alias` or `keep_name`.
|
160
|
+
#
|
161
|
+
# @return [Expr]
|
162
|
+
#
|
163
|
+
# @example
|
164
|
+
# e = Polars.col("foo").alias("bar")
|
165
|
+
# _ = e.meta.undo_aliases.meta == Polars.col("foo")
|
166
|
+
# # => true
|
167
|
+
# e = Polars.col("foo").sum.over("bar")
|
168
|
+
# _ = e.name.keep.meta.undo_aliases.meta == e
|
169
|
+
# # => true
|
170
|
+
def undo_aliases
|
171
|
+
Utils.wrap_expr(_rbexpr.meta_undo_aliases)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Turn this expression in a selector.
|
175
|
+
#
|
176
|
+
# @return [Expr]
|
177
|
+
def _as_selector
|
178
|
+
Utils.wrap_expr(_rbexpr._meta_as_selector)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Add selectors.
|
182
|
+
#
|
183
|
+
# @return [Expr]
|
184
|
+
def _selector_add(other)
|
185
|
+
Utils.wrap_expr(_rbexpr._meta_selector_add(other._rbexpr))
|
186
|
+
end
|
187
|
+
|
188
|
+
# Subtract selectors.
|
189
|
+
#
|
190
|
+
# @return [Expr]
|
191
|
+
def _selector_sub(other)
|
192
|
+
Utils.wrap_expr(_rbexpr._meta_selector_sub(other._rbexpr))
|
193
|
+
end
|
194
|
+
|
195
|
+
# & selectors.
|
196
|
+
#
|
197
|
+
# @return [Expr]
|
198
|
+
def _selector_and(other)
|
199
|
+
Utils.wrap_expr(_rbexpr._meta_selector_and(other._rbexpr))
|
200
|
+
end
|
201
|
+
|
202
|
+
# Format the expression as a tree.
|
203
|
+
#
|
204
|
+
# @param return_as_string [Boolean]
|
205
|
+
# If true, return as string rather than printing to stdout.
|
206
|
+
#
|
207
|
+
# @return [String]
|
208
|
+
#
|
209
|
+
# @example
|
210
|
+
# e = (Polars.col("foo") * Polars.col("bar")).sum.over(Polars.col("ham")) / 2
|
211
|
+
# e.meta.tree_format(return_as_string: true)
|
212
|
+
def tree_format(return_as_string: false)
|
213
|
+
s = _rbexpr.meta_tree_format
|
214
|
+
if return_as_string
|
215
|
+
s
|
216
|
+
else
|
217
|
+
puts s
|
218
|
+
nil
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|