polars-df 0.20.0-x64-mingw-ucrt → 0.21.1-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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/Cargo.lock +192 -186
  4. data/LICENSE-THIRD-PARTY.txt +2153 -2532
  5. data/LICENSE.txt +1 -1
  6. data/lib/polars/3.2/polars.so +0 -0
  7. data/lib/polars/3.3/polars.so +0 -0
  8. data/lib/polars/3.4/polars.so +0 -0
  9. data/lib/polars/array_expr.rb +382 -3
  10. data/lib/polars/array_name_space.rb +281 -0
  11. data/lib/polars/binary_expr.rb +67 -0
  12. data/lib/polars/binary_name_space.rb +43 -0
  13. data/lib/polars/cat_expr.rb +224 -0
  14. data/lib/polars/cat_name_space.rb +130 -32
  15. data/lib/polars/catalog/unity/catalog_info.rb +20 -0
  16. data/lib/polars/catalog/unity/column_info.rb +31 -0
  17. data/lib/polars/catalog/unity/namespace_info.rb +21 -0
  18. data/lib/polars/catalog/unity/table_info.rb +50 -0
  19. data/lib/polars/catalog.rb +448 -0
  20. data/lib/polars/config.rb +2 -2
  21. data/lib/polars/convert.rb +12 -2
  22. data/lib/polars/data_frame.rb +834 -48
  23. data/lib/polars/data_type_expr.rb +52 -0
  24. data/lib/polars/data_types.rb +61 -5
  25. data/lib/polars/date_time_expr.rb +251 -0
  26. data/lib/polars/date_time_name_space.rb +299 -0
  27. data/lib/polars/exceptions.rb +7 -2
  28. data/lib/polars/expr.rb +1247 -211
  29. data/lib/polars/functions/col.rb +6 -5
  30. data/lib/polars/functions/datatype.rb +21 -0
  31. data/lib/polars/functions/lazy.rb +127 -15
  32. data/lib/polars/functions/repeat.rb +4 -0
  33. data/lib/polars/io/csv.rb +19 -1
  34. data/lib/polars/io/json.rb +16 -0
  35. data/lib/polars/io/ndjson.rb +13 -0
  36. data/lib/polars/io/parquet.rb +70 -66
  37. data/lib/polars/io/scan_options.rb +47 -0
  38. data/lib/polars/lazy_frame.rb +1099 -95
  39. data/lib/polars/list_expr.rb +400 -11
  40. data/lib/polars/list_name_space.rb +321 -5
  41. data/lib/polars/meta_expr.rb +71 -22
  42. data/lib/polars/name_expr.rb +36 -0
  43. data/lib/polars/scan_cast_options.rb +64 -0
  44. data/lib/polars/schema.rb +84 -3
  45. data/lib/polars/selector.rb +210 -0
  46. data/lib/polars/selectors.rb +932 -203
  47. data/lib/polars/series.rb +1083 -63
  48. data/lib/polars/string_expr.rb +435 -9
  49. data/lib/polars/string_name_space.rb +729 -45
  50. data/lib/polars/struct_expr.rb +103 -0
  51. data/lib/polars/struct_name_space.rb +19 -1
  52. data/lib/polars/utils/parse.rb +40 -0
  53. data/lib/polars/utils/various.rb +18 -1
  54. data/lib/polars/utils.rb +9 -1
  55. data/lib/polars/version.rb +1 -1
  56. data/lib/polars.rb +10 -0
  57. metadata +12 -2
@@ -18,6 +18,68 @@ module Polars
18
18
  s[item]
19
19
  end
20
20
 
21
+ # Offset by `n` business days.
22
+ #
23
+ # @note
24
+ # This functionality is considered **unstable**. It may be changed
25
+ # at any point without it being considered a breaking change.
26
+ #
27
+ # @param n [Object]
28
+ # Number of business days to offset by. Can be a single number of an
29
+ # expression.
30
+ # @param week_mask [Array]
31
+ # Which days of the week to count. The default is Monday to Friday.
32
+ # If you wanted to count only Monday to Thursday, you would pass
33
+ # `[true, true, true, true, false, false, false]`.
34
+ # roll
35
+ # What to do when the start date lands on a non-business day. Options are:
36
+ #
37
+ # - `'raise'`: raise an error
38
+ # - `'forward'`: move to the next business day
39
+ # - `'backward'`: move to the previous business day
40
+ #
41
+ # @return [Series]
42
+ #
43
+ # @example
44
+ # s = Polars::Series.new("start", [Date.new(2020, 1, 1), Date.new(2020, 1, 2)])
45
+ # s.dt.add_business_days(5)
46
+ # # =>
47
+ # # shape: (2,)
48
+ # # Series: 'start' [date]
49
+ # # [
50
+ # # 2020-01-08
51
+ # # 2020-01-09
52
+ # # ]
53
+ #
54
+ # @example You can pass a custom weekend - for example, if you only take Sunday off:
55
+ # week_mask = [true, true, true, true, true, true, false]
56
+ # s.dt.add_business_days(5, week_mask: week_mask)
57
+ # # =>
58
+ # # shape: (2,)
59
+ # # Series: 'start' [date]
60
+ # # [
61
+ # # 2020-01-07
62
+ # # 2020-01-08
63
+ # # ]
64
+ #
65
+ # @example Roll all dates forwards to the next business day:
66
+ # s = Polars::Series.new("start", [Date.new(2020, 1, 5), Date.new(2020, 1, 6)])
67
+ # s.dt.add_business_days(0, roll: "forward")
68
+ # # =>
69
+ # # shape: (2,)
70
+ # # Series: 'start' [date]
71
+ # # [
72
+ # # 2020-01-06
73
+ # # 2020-01-06
74
+ # # ]
75
+ def add_business_days(
76
+ n,
77
+ week_mask: [true, true, true, true, true, false, false],
78
+ roll: "raise"
79
+ )
80
+ super
81
+ end
82
+
21
83
  # Return minimum as Ruby object.
22
84
  #
23
85
  # @return [Object]
@@ -139,6 +201,74 @@ module Polars
139
201
  super
140
202
  end
141
203
 
204
+ # Extract the millennium from underlying representation.
205
+ #
206
+ # Applies to Date and Datetime columns.
207
+ #
208
+ # Returns the millennium number in the calendar date.
209
+ #
210
+ # @return [Series]
211
+ #
212
+ # @example
213
+ # s = Polars::Series.new(
214
+ # "dt",
215
+ # [
216
+ # Date.new(999, 12, 31),
217
+ # Date.new(1897, 5, 7),
218
+ # Date.new(2000, 1, 1),
219
+ # Date.new(2001, 7, 5),
220
+ # Date.new(3002, 10, 20)
221
+ # ]
222
+ # )
223
+ # s.dt.millennium
224
+ # # =>
225
+ # # shape: (5,)
226
+ # # Series: 'dt' [i32]
227
+ # # [
228
+ # # 1
229
+ # # 2
230
+ # # 2
231
+ # # 3
232
+ # # 4
233
+ # # ]
234
+ def millennium
235
+ super
236
+ end
237
+
238
+ # Extract the century from underlying representation.
239
+ #
240
+ # Applies to Date and Datetime columns.
241
+ #
242
+ # Returns the century number in the calendar date.
243
+ #
244
+ # @return [Series]
245
+ #
246
+ # @example
247
+ # s = Polars::Series.new(
248
+ # "dt",
249
+ # [
250
+ # Date.new(999, 12, 31),
251
+ # Date.new(1897, 5, 7),
252
+ # Date.new(2000, 1, 1),
253
+ # Date.new(2001, 7, 5),
254
+ # Date.new(3002, 10, 20)
255
+ # ]
256
+ # )
257
+ # s.dt.century
258
+ # # =>
259
+ # # shape: (5,)
260
+ # # Series: 'dt' [i32]
261
+ # # [
262
+ # # 10
263
+ # # 19
264
+ # # 20
265
+ # # 21
266
+ # # 31
267
+ # # ]
268
+ def century
269
+ super
270
+ end
271
+
142
272
  # Extract the year from the underlying date representation.
143
273
  #
144
274
  # Applies to Date and Datetime columns.
@@ -161,6 +291,69 @@ module Polars
161
291
  super
162
292
  end
163
293
 
294
+ # Determine whether each day lands on a business day.
295
+ #
296
+ # @note
297
+ # This functionality is considered **unstable**. It may be changed
298
+ # at any point without it being considered a breaking change.
299
+ #
300
+ # @param week_mask [Array]
301
+ # Which days of the week to count. The default is Monday to Friday.
302
+ # If you wanted to count only Monday to Thursday, you would pass
303
+ # `(True, True, True, True, False, False, False)`.
304
+ #
305
+ # @return [Series]
306
+ #
307
+ # @example
308
+ # s = Polars::Series.new([Date.new(2020, 1, 3), Date.new(2020, 1, 5)])
309
+ # s.dt.is_business_day
310
+ # # =>
311
+ # # shape: (2,)
312
+ # # Series: '' [bool]
313
+ # # [
314
+ # # true
315
+ # # false
316
+ # # ]
317
+ #
318
+ # @example You can pass a custom weekend - for example, if you only take Sunday off:
319
+ # week_mask = [true, true, true, true, true, true, false]
320
+ # s.dt.is_business_day(week_mask: week_mask)
321
+ # # =>
322
+ # # shape: (2,)
323
+ # # Series: '' [bool]
324
+ # # [
325
+ # # true
326
+ # # false
327
+ # # ]
328
+ def is_business_day(
329
+ week_mask: [true, true, true, true, true, false, false]
330
+ )
331
+ super
332
+ end
333
+
334
+ # Determine whether the year of the underlying date representation is a leap year.
335
+ #
336
+ # Applies to Date and Datetime columns.
337
+ #
338
+ # @return [Series]
339
+ #
340
+ # @example
341
+ # s = Polars::Series.new(
342
+ # "date", [Date.new(2000, 1, 1), Date.new(2001, 1, 1), Date.new(2002, 1, 1)]
343
+ # )
344
+ # s.dt.is_leap_year
345
+ # # =>
346
+ # # shape: (3,)
347
+ # # Series: 'date' [bool]
348
+ # # [
349
+ # # true
350
+ # # false
351
+ # # false
352
+ # # ]
353
+ def is_leap_year
354
+ super
355
+ end
356
+
164
357
  # Extract ISO year from underlying Date representation.
165
358
  #
166
359
  # Applies to Date and Datetime columns.
@@ -346,6 +539,48 @@ module Polars
346
539
  super
347
540
  end
348
541
 
542
+ # Extract (local) time.
543
+ #
544
+ # Applies to Date/Datetime/Time columns.
545
+ #
546
+ # @return
547
+ #
548
+ # @example
549
+ # ser = Polars::Series.new([DateTime.new(2021, 1, 2, 5)]).dt.replace_time_zone(
550
+ # "Asia/Kathmandu"
551
+ # )
552
+ # ser.dt.time
553
+ # # =>
554
+ # # shape: (1,)
555
+ # # Series: '' [time]
556
+ # # [
557
+ # # 05:00:00
558
+ # # ]
559
+ def time
560
+ super
561
+ end
562
+
563
+ # Extract (local) date.
564
+ #
565
+ # Applies to Date/Datetime columns.
566
+ #
567
+ # @return [Series]
568
+ #
569
+ # @example
570
+ # ser = Polars::Series.new([DateTime.new(2021, 1, 2, 5)]).dt.replace_time_zone(
571
+ # "Asia/Kathmandu"
572
+ # )
573
+ # ser.dt.date
574
+ # # =>
575
+ # # shape: (1,)
576
+ # # Series: '' [date]
577
+ # # [
578
+ # # 2021-01-02
579
+ # # ]
580
+ def date
581
+ super
582
+ end
583
+
349
584
  # Extract the hour from the underlying DateTime representation.
350
585
  #
351
586
  # Applies to Datetime columns.
@@ -1276,6 +1511,21 @@ module Polars
1276
1511
  super
1277
1512
  end
1278
1513
 
1514
+ # Create a naive Datetime from an existing Date/Datetime expression and a Time.
1515
+ #
1516
+ # If the underlying expression is a Datetime then its time component is replaced,
1517
+ # and if it is a Date then a new Datetime is created by combining the two values.
1518
+ #
1519
+ # @param time [Object]
1520
+ # A Ruby time literal or Series of the same length as this Series.
1521
+ # @param time_unit ['ns', 'us', 'ms']
1522
+ # Unit of time.
1523
+ #
1524
+ # @return [Series]
1525
+ def combine(time, time_unit: "us")
1526
+ super
1527
+ end
1528
+
1279
1529
  # Roll backward to the first day of the month.
1280
1530
  #
1281
1531
  # @return [Series]
@@ -1370,5 +1620,54 @@ module Polars
1370
1620
  def dst_offset
1371
1621
  super
1372
1622
  end
1623
+
1624
+ # Replace time unit.
1625
+ #
1626
+ # @param year [Object]
1627
+ # Literal or Series.
1628
+ # @param month [Object]
1629
+ # Literal or Series, ranging from 1-12.
1630
+ # @param day [Object]
1631
+ # Literal or Series, ranging from 1-31.
1632
+ # @param hour [Object]
1633
+ # Literal or Series, ranging from 0-23.
1634
+ # @param minute [Object]
1635
+ # Literal or Series, ranging from 0-59.
1636
+ # @param second [Object]
1637
+ # Literal or Series, ranging from 0-59.
1638
+ # @param microsecond [Object]
1639
+ # Literal or Series, ranging from 0-999999.
1640
+ # @param ambiguous [String]
1641
+ # Determine how to deal with ambiguous datetimes:
1642
+ #
1643
+ # - `'raise'` (default): raise
1644
+ # - `'earliest'`: use the earliest datetime
1645
+ # - `'latest'`: use the latest datetime
1646
+ # - `'null'`: set to null
1647
+ #
1648
+ # @return [Series]
1649
+ #
1650
+ # @example
1651
+ # s = Polars::Series.new("date", [Date.new(2013, 1, 1), Date.new(2024, 1, 2)])
1652
+ # s.dt.replace(year: 1800)
1653
+ # # =>
1654
+ # # shape: (2,)
1655
+ # # Series: 'date' [date]
1656
+ # # [
1657
+ # # 1800-01-01
1658
+ # # 1800-01-02
1659
+ # # ]
1660
+ def replace(
1661
+ year: nil,
1662
+ month: nil,
1663
+ day: nil,
1664
+ hour: nil,
1665
+ minute: nil,
1666
+ second: nil,
1667
+ microsecond: nil,
1668
+ ambiguous: "raise"
1669
+ )
1670
+ super
1671
+ end
1373
1672
  end
1374
1673
  end
@@ -24,10 +24,15 @@ module Polars
24
24
  class TooManyRowsReturned < RowsException; end
25
25
 
26
26
  # @private
27
- class AssertionError < Error; end
27
+ # Exception raised when Polars could not perform an underlying computation.
28
+ class ComputeError < Error; end
28
29
 
29
30
  # @private
30
- class ComputeError < Error; end
31
+ # Exception raised when a column name is duplicated.
32
+ class DuplicateError < Error; end
33
+
34
+ # @private
35
+ class AssertionError < Error; end
31
36
 
32
37
  # @private
33
38
  class Todo < Error