polars-df 0.13.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/Cargo.lock +1368 -319
  4. data/LICENSE.txt +1 -0
  5. data/README.md +1 -2
  6. data/ext/polars/Cargo.toml +15 -6
  7. data/ext/polars/src/batched_csv.rs +10 -13
  8. data/ext/polars/src/conversion/any_value.rs +37 -21
  9. data/ext/polars/src/conversion/chunked_array.rs +3 -3
  10. data/ext/polars/src/conversion/mod.rs +159 -46
  11. data/ext/polars/src/dataframe/construction.rs +4 -7
  12. data/ext/polars/src/dataframe/export.rs +9 -2
  13. data/ext/polars/src/dataframe/general.rs +22 -16
  14. data/ext/polars/src/dataframe/io.rs +78 -174
  15. data/ext/polars/src/dataframe/mod.rs +1 -0
  16. data/ext/polars/src/dataframe/serde.rs +15 -0
  17. data/ext/polars/src/error.rs +31 -48
  18. data/ext/polars/src/exceptions.rs +24 -0
  19. data/ext/polars/src/expr/binary.rs +4 -42
  20. data/ext/polars/src/expr/datetime.rs +16 -7
  21. data/ext/polars/src/expr/general.rs +14 -23
  22. data/ext/polars/src/expr/list.rs +18 -11
  23. data/ext/polars/src/expr/name.rs +3 -2
  24. data/ext/polars/src/expr/rolling.rs +6 -7
  25. data/ext/polars/src/expr/string.rs +17 -37
  26. data/ext/polars/src/file.rs +59 -22
  27. data/ext/polars/src/functions/business.rs +15 -0
  28. data/ext/polars/src/functions/io.rs +6 -6
  29. data/ext/polars/src/functions/lazy.rs +17 -8
  30. data/ext/polars/src/functions/mod.rs +1 -0
  31. data/ext/polars/src/functions/range.rs +4 -2
  32. data/ext/polars/src/interop/arrow/mod.rs +1 -0
  33. data/ext/polars/src/interop/arrow/to_ruby.rs +83 -0
  34. data/ext/polars/src/interop/mod.rs +1 -0
  35. data/ext/polars/src/lazyframe/general.rs +877 -0
  36. data/ext/polars/src/lazyframe/mod.rs +3 -825
  37. data/ext/polars/src/lazyframe/serde.rs +31 -0
  38. data/ext/polars/src/lib.rs +44 -13
  39. data/ext/polars/src/map/dataframe.rs +46 -14
  40. data/ext/polars/src/map/lazy.rs +65 -4
  41. data/ext/polars/src/map/mod.rs +17 -16
  42. data/ext/polars/src/map/series.rs +106 -64
  43. data/ext/polars/src/on_startup.rs +2 -2
  44. data/ext/polars/src/series/aggregation.rs +1 -5
  45. data/ext/polars/src/series/arithmetic.rs +10 -10
  46. data/ext/polars/src/series/construction.rs +52 -25
  47. data/ext/polars/src/series/export.rs +1 -1
  48. data/ext/polars/src/series/general.rs +643 -0
  49. data/ext/polars/src/series/import.rs +55 -0
  50. data/ext/polars/src/series/mod.rs +11 -638
  51. data/ext/polars/src/series/scatter.rs +2 -2
  52. data/ext/polars/src/utils.rs +0 -20
  53. data/lib/polars/batched_csv_reader.rb +0 -2
  54. data/lib/polars/binary_expr.rb +133 -9
  55. data/lib/polars/binary_name_space.rb +101 -6
  56. data/lib/polars/config.rb +4 -0
  57. data/lib/polars/data_frame.rb +285 -62
  58. data/lib/polars/data_type_group.rb +28 -0
  59. data/lib/polars/data_types.rb +2 -0
  60. data/lib/polars/date_time_expr.rb +244 -0
  61. data/lib/polars/date_time_name_space.rb +87 -0
  62. data/lib/polars/expr.rb +109 -8
  63. data/lib/polars/functions/as_datatype.rb +51 -2
  64. data/lib/polars/functions/col.rb +1 -1
  65. data/lib/polars/functions/eager.rb +1 -3
  66. data/lib/polars/functions/lazy.rb +88 -10
  67. data/lib/polars/functions/range/time_range.rb +21 -21
  68. data/lib/polars/io/csv.rb +14 -16
  69. data/lib/polars/io/database.rb +2 -2
  70. data/lib/polars/io/ipc.rb +14 -12
  71. data/lib/polars/io/ndjson.rb +10 -0
  72. data/lib/polars/io/parquet.rb +168 -111
  73. data/lib/polars/lazy_frame.rb +649 -15
  74. data/lib/polars/list_name_space.rb +169 -0
  75. data/lib/polars/selectors.rb +1144 -0
  76. data/lib/polars/series.rb +470 -40
  77. data/lib/polars/string_cache.rb +27 -1
  78. data/lib/polars/string_expr.rb +0 -1
  79. data/lib/polars/string_name_space.rb +73 -3
  80. data/lib/polars/struct_name_space.rb +31 -7
  81. data/lib/polars/utils/various.rb +5 -1
  82. data/lib/polars/utils.rb +45 -10
  83. data/lib/polars/version.rb +1 -1
  84. data/lib/polars.rb +2 -1
  85. metadata +14 -4
  86. data/lib/polars/functions.rb +0 -57
@@ -133,6 +133,17 @@ module Polars
133
133
  # Sum all the arrays in the list.
134
134
  #
135
135
  # @return [Series]
136
+ #
137
+ # @example
138
+ # s = Polars::Series.new("values", [[1], [2, 3]])
139
+ # s.list.sum
140
+ # # =>
141
+ # # shape: (2,)
142
+ # # Series: 'values' [i64]
143
+ # # [
144
+ # # 1
145
+ # # 5
146
+ # # ]
136
147
  def sum
137
148
  super
138
149
  end
@@ -140,6 +151,17 @@ module Polars
140
151
  # Compute the max value of the arrays in the list.
141
152
  #
142
153
  # @return [Series]
154
+ #
155
+ # @example
156
+ # s = Polars::Series.new("values", [[4, 1], [2, 3]])
157
+ # s.list.max
158
+ # # =>
159
+ # # shape: (2,)
160
+ # # Series: 'values' [i64]
161
+ # # [
162
+ # # 4
163
+ # # 3
164
+ # # ]
143
165
  def max
144
166
  super
145
167
  end
@@ -147,6 +169,17 @@ module Polars
147
169
  # Compute the min value of the arrays in the list.
148
170
  #
149
171
  # @return [Series]
172
+ #
173
+ # @example
174
+ # s = Polars::Series.new("values", [[4, 1], [2, 3]])
175
+ # s.list.min
176
+ # # =>
177
+ # # shape: (2,)
178
+ # # Series: 'values' [i64]
179
+ # # [
180
+ # # 1
181
+ # # 2
182
+ # # ]
150
183
  def min
151
184
  super
152
185
  end
@@ -154,6 +187,17 @@ module Polars
154
187
  # Compute the mean value of the arrays in the list.
155
188
  #
156
189
  # @return [Series]
190
+ #
191
+ # @example
192
+ # s = Polars::Series.new("values", [[3, 1], [3, 3]])
193
+ # s.list.mean
194
+ # # =>
195
+ # # shape: (2,)
196
+ # # Series: 'values' [f64]
197
+ # # [
198
+ # # 2.0
199
+ # # 3.0
200
+ # # ]
157
201
  def mean
158
202
  super
159
203
  end
@@ -161,6 +205,27 @@ module Polars
161
205
  # Sort the arrays in the list.
162
206
  #
163
207
  # @return [Series]
208
+ #
209
+ # @example
210
+ # s = Polars::Series.new("a", [[3, 2, 1], [9, 1, 2]])
211
+ # s.list.sort
212
+ # # =>
213
+ # # shape: (2,)
214
+ # # Series: 'a' [list[i64]]
215
+ # # [
216
+ # # [1, 2, 3]
217
+ # # [1, 2, 9]
218
+ # # ]
219
+ #
220
+ # @example
221
+ # s.list.sort(reverse: true)
222
+ # # =>
223
+ # # shape: (2,)
224
+ # # Series: 'a' [list[i64]]
225
+ # # [
226
+ # # [3, 2, 1]
227
+ # # [9, 2, 1]
228
+ # # ]
164
229
  def sort(reverse: false)
165
230
  super
166
231
  end
@@ -168,6 +233,17 @@ module Polars
168
233
  # Reverse the arrays in the list.
169
234
  #
170
235
  # @return [Series]
236
+ #
237
+ # @example
238
+ # s = Polars::Series.new("a", [[3, 2, 1], [9, 1, 2]])
239
+ # s.list.reverse
240
+ # # =>
241
+ # # shape: (2,)
242
+ # # Series: 'a' [list[i64]]
243
+ # # [
244
+ # # [1, 2, 3]
245
+ # # [2, 1, 9]
246
+ # # ]
171
247
  def reverse
172
248
  super
173
249
  end
@@ -175,6 +251,17 @@ module Polars
175
251
  # Get the unique/distinct values in the list.
176
252
  #
177
253
  # @return [Series]
254
+ #
255
+ # @example
256
+ # s = Polars::Series.new("a", [[1, 1, 2], [2, 3, 3]])
257
+ # s.list.unique()
258
+ # # =>
259
+ # # shape: (2,)
260
+ # # Series: 'a' [list[i64]]
261
+ # # [
262
+ # # [1, 2]
263
+ # # [2, 3]
264
+ # # ]
178
265
  def unique
179
266
  super
180
267
  end
@@ -185,6 +272,18 @@ module Polars
185
272
  # Columns to concat into a List Series
186
273
  #
187
274
  # @return [Series]
275
+ #
276
+ # @example
277
+ # s1 = Polars::Series.new("a", [["a", "b"], ["c"]])
278
+ # s2 = Polars::Series.new("b", [["c"], ["d", nil]])
279
+ # s1.list.concat(s2)
280
+ # # =>
281
+ # # shape: (2,)
282
+ # # Series: 'a' [list[str]]
283
+ # # [
284
+ # # ["a", "b", "c"]
285
+ # # ["c", "d", null]
286
+ # # ]
188
287
  def concat(other)
189
288
  super
190
289
  end
@@ -203,6 +302,18 @@ module Polars
203
302
  # false -> raise an error
204
303
  #
205
304
  # @return [Series]
305
+ #
306
+ # @example
307
+ # s = Polars::Series.new("a", [[3, 2, 1], [], [1, 2]])
308
+ # s.list.get(0, null_on_oob: true)
309
+ # # =>
310
+ # # shape: (3,)
311
+ # # Series: 'a' [i64]
312
+ # # [
313
+ # # 3
314
+ # # null
315
+ # # 1
316
+ # # ]
206
317
  def get(index, null_on_oob: false)
207
318
  super
208
319
  end
@@ -240,6 +351,18 @@ module Polars
240
351
  # Get the first value of the sublists.
241
352
  #
242
353
  # @return [Series]
354
+ #
355
+ # @example
356
+ # s = Polars::Series.new("a", [[3, 2, 1], [], [1, 2]])
357
+ # s.list.first
358
+ # # =>
359
+ # # shape: (3,)
360
+ # # Series: 'a' [i64]
361
+ # # [
362
+ # # 3
363
+ # # null
364
+ # # 1
365
+ # # ]
243
366
  def first
244
367
  super
245
368
  end
@@ -247,6 +370,18 @@ module Polars
247
370
  # Get the last value of the sublists.
248
371
  #
249
372
  # @return [Series]
373
+ #
374
+ # @example
375
+ # s = Polars::Series.new("a", [[3, 2, 1], [], [1, 2]])
376
+ # s.list.last
377
+ # # =>
378
+ # # shape: (3,)
379
+ # # Series: 'a' [i64]
380
+ # # [
381
+ # # 1
382
+ # # null
383
+ # # 2
384
+ # # ]
250
385
  def last
251
386
  super
252
387
  end
@@ -257,6 +392,18 @@ module Polars
257
392
  # Item that will be checked for membership.
258
393
  #
259
394
  # @return [Series]
395
+ #
396
+ # @example
397
+ # s = Polars::Series.new("a", [[3, 2, 1], [], [1, 2]])
398
+ # s.list.contains(1)
399
+ # # =>
400
+ # # shape: (3,)
401
+ # # Series: 'a' [bool]
402
+ # # [
403
+ # # true
404
+ # # false
405
+ # # true
406
+ # # ]
260
407
  def contains(item)
261
408
  super
262
409
  end
@@ -264,6 +411,17 @@ module Polars
264
411
  # Retrieve the index of the minimal value in every sublist.
265
412
  #
266
413
  # @return [Series]
414
+ #
415
+ # @example
416
+ # s = Polars::Series.new("a", [[1, 2], [2, 1]])
417
+ # s.list.arg_min
418
+ # # =>
419
+ # # shape: (2,)
420
+ # # Series: 'a' [u32]
421
+ # # [
422
+ # # 0
423
+ # # 1
424
+ # # ]
267
425
  def arg_min
268
426
  super
269
427
  end
@@ -271,6 +429,17 @@ module Polars
271
429
  # Retrieve the index of the maximum value in every sublist.
272
430
  #
273
431
  # @return [Series]
432
+ #
433
+ # @example
434
+ # s = Polars::Series.new("a", [[1, 2], [2, 1]])
435
+ # s.list.arg_max
436
+ # # =>
437
+ # # shape: (2,)
438
+ # # Series: 'a' [u32]
439
+ # # [
440
+ # # 1
441
+ # # 0
442
+ # # ]
274
443
  def arg_max
275
444
  super
276
445
  end