polars-df 0.10.0-x86_64-linux-musl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -0
  3. data/CHANGELOG.md +175 -0
  4. data/Cargo.lock +2536 -0
  5. data/Cargo.toml +6 -0
  6. data/LICENSE-THIRD-PARTY.txt +38726 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +437 -0
  9. data/lib/polars/3.1/polars.so +0 -0
  10. data/lib/polars/3.2/polars.so +0 -0
  11. data/lib/polars/3.3/polars.so +0 -0
  12. data/lib/polars/array_expr.rb +537 -0
  13. data/lib/polars/array_name_space.rb +423 -0
  14. data/lib/polars/batched_csv_reader.rb +98 -0
  15. data/lib/polars/binary_expr.rb +77 -0
  16. data/lib/polars/binary_name_space.rb +66 -0
  17. data/lib/polars/cat_expr.rb +72 -0
  18. data/lib/polars/cat_name_space.rb +125 -0
  19. data/lib/polars/config.rb +530 -0
  20. data/lib/polars/convert.rb +93 -0
  21. data/lib/polars/data_frame.rb +5418 -0
  22. data/lib/polars/data_types.rb +466 -0
  23. data/lib/polars/date_time_expr.rb +1444 -0
  24. data/lib/polars/date_time_name_space.rb +1484 -0
  25. data/lib/polars/dynamic_group_by.rb +52 -0
  26. data/lib/polars/exceptions.rb +31 -0
  27. data/lib/polars/expr.rb +6105 -0
  28. data/lib/polars/expr_dispatch.rb +22 -0
  29. data/lib/polars/functions/aggregation/horizontal.rb +246 -0
  30. data/lib/polars/functions/aggregation/vertical.rb +282 -0
  31. data/lib/polars/functions/as_datatype.rb +248 -0
  32. data/lib/polars/functions/col.rb +47 -0
  33. data/lib/polars/functions/eager.rb +182 -0
  34. data/lib/polars/functions/lazy.rb +1280 -0
  35. data/lib/polars/functions/len.rb +49 -0
  36. data/lib/polars/functions/lit.rb +35 -0
  37. data/lib/polars/functions/random.rb +16 -0
  38. data/lib/polars/functions/range/date_range.rb +103 -0
  39. data/lib/polars/functions/range/int_range.rb +51 -0
  40. data/lib/polars/functions/repeat.rb +144 -0
  41. data/lib/polars/functions/whenthen.rb +96 -0
  42. data/lib/polars/functions.rb +57 -0
  43. data/lib/polars/group_by.rb +548 -0
  44. data/lib/polars/io.rb +890 -0
  45. data/lib/polars/lazy_frame.rb +2833 -0
  46. data/lib/polars/lazy_group_by.rb +84 -0
  47. data/lib/polars/list_expr.rb +791 -0
  48. data/lib/polars/list_name_space.rb +445 -0
  49. data/lib/polars/meta_expr.rb +222 -0
  50. data/lib/polars/name_expr.rb +198 -0
  51. data/lib/polars/plot.rb +109 -0
  52. data/lib/polars/rolling_group_by.rb +37 -0
  53. data/lib/polars/series.rb +4527 -0
  54. data/lib/polars/slice.rb +104 -0
  55. data/lib/polars/sql_context.rb +194 -0
  56. data/lib/polars/string_cache.rb +75 -0
  57. data/lib/polars/string_expr.rb +1519 -0
  58. data/lib/polars/string_name_space.rb +810 -0
  59. data/lib/polars/struct_expr.rb +98 -0
  60. data/lib/polars/struct_name_space.rb +96 -0
  61. data/lib/polars/testing.rb +507 -0
  62. data/lib/polars/utils.rb +422 -0
  63. data/lib/polars/version.rb +4 -0
  64. data/lib/polars/whenthen.rb +83 -0
  65. data/lib/polars-df.rb +1 -0
  66. data/lib/polars.rb +72 -0
  67. metadata +125 -0
@@ -0,0 +1,1484 @@
1
+ module Polars
2
+ # Series.dt namespace.
3
+ class DateTimeNameSpace
4
+ include ExprDispatch
5
+
6
+ self._accessor = "dt"
7
+
8
+ # @private
9
+ def initialize(series)
10
+ self._s = series._s
11
+ end
12
+
13
+ # Get item.
14
+ #
15
+ # @return [Object]
16
+ def [](item)
17
+ s = Utils.wrap_s(_s)
18
+ s[item]
19
+ end
20
+
21
+ # Return minimum as Ruby object.
22
+ #
23
+ # @return [Object]
24
+ #
25
+ # @example
26
+ # s = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
27
+ # s.dt.min
28
+ # # => 2001-01-01 00:00:00 UTC
29
+ def min
30
+ Utils.wrap_s(_s).min
31
+ end
32
+
33
+ # Return maximum as Ruby object.
34
+ #
35
+ # @return [Object]
36
+ #
37
+ # @example
38
+ # s = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
39
+ # s.dt.max
40
+ # # => 2001-01-03 00:00:00 UTC
41
+ def max
42
+ Utils.wrap_s(_s).max
43
+ end
44
+
45
+ # Return median as Ruby object.
46
+ #
47
+ # @return [Object]
48
+ #
49
+ # @example
50
+ # date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
51
+ # # =>
52
+ # # shape: (3,)
53
+ # # Series: '' [datetime[μs]]
54
+ # # [
55
+ # # 2001-01-01 00:00:00
56
+ # # 2001-01-02 00:00:00
57
+ # # 2001-01-03 00:00:00
58
+ # # ]
59
+ #
60
+ # @example
61
+ # date.dt.median
62
+ # # => 2001-01-02 00:00:00 UTC
63
+ def median
64
+ s = Utils.wrap_s(_s)
65
+ out = s.median
66
+ if !out.nil?
67
+ if s.dtype == Date
68
+ return Utils._to_ruby_date(out.to_i)
69
+ else
70
+ return Utils._to_ruby_datetime(out.to_i, s.time_unit)
71
+ end
72
+ end
73
+ nil
74
+ end
75
+
76
+ # Return mean as Ruby object.
77
+ #
78
+ # @return [Object]
79
+ #
80
+ # @example
81
+ # date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
82
+ # # =>
83
+ # # shape: (3,)
84
+ # # Series: '' [datetime[μs]]
85
+ # # [
86
+ # # 2001-01-01 00:00:00
87
+ # # 2001-01-02 00:00:00
88
+ # # 2001-01-03 00:00:00
89
+ # # ]
90
+ #
91
+ # @example
92
+ # date.dt.mean
93
+ # # => 2001-01-02 00:00:00 UTC
94
+ def mean
95
+ s = Utils.wrap_s(_s)
96
+ out = s.mean.to_i
97
+ if !out.nil?
98
+ if s.dtype == Date
99
+ return Utils._to_ruby_date(out.to_i)
100
+ else
101
+ return Utils._to_ruby_datetime(out.to_i, s.time_unit)
102
+ end
103
+ end
104
+ nil
105
+ end
106
+
107
+ # Format Date/datetime with a formatting rule.
108
+ #
109
+ # See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
110
+ #
111
+ # @return [Series]
112
+ #
113
+ # @example
114
+ # start = DateTime.new(2001, 1, 1)
115
+ # stop = DateTime.new(2001, 1, 4)
116
+ # date = Polars.date_range(start, stop, "1d")
117
+ # # =>
118
+ # # shape: (4,)
119
+ # # Series: '' [datetime[μs]]
120
+ # # [
121
+ # # 2001-01-01 00:00:00
122
+ # # 2001-01-02 00:00:00
123
+ # # 2001-01-03 00:00:00
124
+ # # 2001-01-04 00:00:00
125
+ # # ]
126
+ #
127
+ # @example
128
+ # date.dt.strftime("%Y-%m-%d")
129
+ # # =>
130
+ # # shape: (4,)
131
+ # # Series: '' [str]
132
+ # # [
133
+ # # "2001-01-01"
134
+ # # "2001-01-02"
135
+ # # "2001-01-03"
136
+ # # "2001-01-04"
137
+ # # ]
138
+ def strftime(fmt)
139
+ super
140
+ end
141
+
142
+ # Extract the year from the underlying date representation.
143
+ #
144
+ # Applies to Date and Datetime columns.
145
+ #
146
+ # Returns the year number in the calendar date.
147
+ #
148
+ # @return [Series]
149
+ #
150
+ # @example
151
+ # start = DateTime.new(2001, 1, 1)
152
+ # stop = DateTime.new(2002, 1, 1)
153
+ # date = Polars.date_range(start, stop, "1y")
154
+ # # =>
155
+ # # shape: (2,)
156
+ # # Series: '' [datetime[μs]]
157
+ # # [
158
+ # # 2001-01-01 00:00:00
159
+ # # 2002-01-01 00:00:00
160
+ # # ]
161
+ #
162
+ # @example
163
+ # date.dt.year
164
+ # # =>
165
+ # # shape: (2,)
166
+ # # Series: '' [i32]
167
+ # # [
168
+ # # 2001
169
+ # # 2002
170
+ # # ]
171
+ def year
172
+ super
173
+ end
174
+
175
+ # Extract ISO year from underlying Date representation.
176
+ #
177
+ # Applies to Date and Datetime columns.
178
+ #
179
+ # Returns the year number according to the ISO standard.
180
+ # This may not correspond with the calendar year.
181
+ #
182
+ # @return [Series]
183
+ #
184
+ # @example
185
+ # dt = DateTime.new(2022, 1, 1, 7, 8, 40)
186
+ # Polars::Series.new([dt]).dt.iso_year
187
+ # # =>
188
+ # # shape: (1,)
189
+ # # Series: '' [i32]
190
+ # # [
191
+ # # 2021
192
+ # # ]
193
+ def iso_year
194
+ super
195
+ end
196
+
197
+ # Extract quarter from underlying Date representation.
198
+ #
199
+ # Applies to Date and Datetime columns.
200
+ #
201
+ # Returns the quarter ranging from 1 to 4.
202
+ #
203
+ # @return [Series]
204
+ #
205
+ # @example
206
+ # start = DateTime.new(2001, 1, 1)
207
+ # stop = DateTime.new(2001, 4, 1)
208
+ # date = Polars.date_range(start, stop, "1mo")
209
+ # # =>
210
+ # # shape: (4,)
211
+ # # Series: '' [datetime[μs]]
212
+ # # [
213
+ # # 2001-01-01 00:00:00
214
+ # # 2001-02-01 00:00:00
215
+ # # 2001-03-01 00:00:00
216
+ # # 2001-04-01 00:00:00
217
+ # # ]
218
+ #
219
+ # @example
220
+ # date.dt.quarter
221
+ # # =>
222
+ # # shape: (4,)
223
+ # # Series: '' [i8]
224
+ # # [
225
+ # # 1
226
+ # # 1
227
+ # # 1
228
+ # # 2
229
+ # # ]
230
+ def quarter
231
+ super
232
+ end
233
+
234
+ # Extract the month from the underlying date representation.
235
+ #
236
+ # Applies to Date and Datetime columns.
237
+ #
238
+ # Returns the month number starting from 1.
239
+ # The return value ranges from 1 to 12.
240
+ #
241
+ # @return [Series]
242
+ #
243
+ # @example
244
+ # start = DateTime.new(2001, 1, 1)
245
+ # stop = DateTime.new(2001, 4, 1)
246
+ # date = Polars.date_range(start, stop, "1mo")
247
+ # # =>
248
+ # # shape: (4,)
249
+ # # Series: '' [datetime[μs]]
250
+ # # [
251
+ # # 2001-01-01 00:00:00
252
+ # # 2001-02-01 00:00:00
253
+ # # 2001-03-01 00:00:00
254
+ # # 2001-04-01 00:00:00
255
+ # # ]
256
+ #
257
+ # @example
258
+ # date.dt.month
259
+ # # =>
260
+ # # shape: (4,)
261
+ # # Series: '' [i8]
262
+ # # [
263
+ # # 1
264
+ # # 2
265
+ # # 3
266
+ # # 4
267
+ # # ]
268
+ def month
269
+ super
270
+ end
271
+
272
+ # Extract the week from the underlying date representation.
273
+ #
274
+ # Applies to Date and Datetime columns.
275
+ #
276
+ # Returns the ISO week number starting from 1.
277
+ # The return value ranges from 1 to 53. (The last week of year differs by years.)
278
+ #
279
+ # @return [Series]
280
+ #
281
+ # @example
282
+ # start = DateTime.new(2001, 1, 1)
283
+ # stop = DateTime.new(2001, 4, 1)
284
+ # date = Polars.date_range(start, stop, "1mo")
285
+ # # =>
286
+ # # shape: (4,)
287
+ # # Series: '' [datetime[μs]]
288
+ # # [
289
+ # # 2001-01-01 00:00:00
290
+ # # 2001-02-01 00:00:00
291
+ # # 2001-03-01 00:00:00
292
+ # # 2001-04-01 00:00:00
293
+ # # ]
294
+ #
295
+ # @example
296
+ # date.dt.week
297
+ # # =>
298
+ # # shape: (4,)
299
+ # # Series: '' [i8]
300
+ # # [
301
+ # # 1
302
+ # # 5
303
+ # # 9
304
+ # # 13
305
+ # # ]
306
+ def week
307
+ super
308
+ end
309
+
310
+ # Extract the week day from the underlying date representation.
311
+ #
312
+ # Applies to Date and Datetime columns.
313
+ #
314
+ # Returns the ISO weekday number where monday = 1 and sunday = 7
315
+ #
316
+ # @return [Series]
317
+ #
318
+ # @example
319
+ # start = DateTime.new(2001, 1, 1)
320
+ # stop = DateTime.new(2001, 1, 7)
321
+ # date = Polars.date_range(start, stop, "1d")
322
+ # # =>
323
+ # # shape: (7,)
324
+ # # Series: '' [datetime[μs]]
325
+ # # [
326
+ # # 2001-01-01 00:00:00
327
+ # # 2001-01-02 00:00:00
328
+ # # 2001-01-03 00:00:00
329
+ # # 2001-01-04 00:00:00
330
+ # # 2001-01-05 00:00:00
331
+ # # 2001-01-06 00:00:00
332
+ # # 2001-01-07 00:00:00
333
+ # # ]
334
+ #
335
+ # @example
336
+ # date.dt.weekday
337
+ # # =>
338
+ # # shape: (7,)
339
+ # # Series: '' [i8]
340
+ # # [
341
+ # # 1
342
+ # # 2
343
+ # # 3
344
+ # # 4
345
+ # # 5
346
+ # # 6
347
+ # # 7
348
+ # # ]
349
+ def weekday
350
+ super
351
+ end
352
+
353
+ # Extract the day from the underlying date representation.
354
+ #
355
+ # Applies to Date and Datetime columns.
356
+ #
357
+ # Returns the day of month starting from 1.
358
+ # The return value ranges from 1 to 31. (The last day of month differs by months.)
359
+ #
360
+ # @return [Series]
361
+ #
362
+ # @example
363
+ # start = DateTime.new(2001, 1, 1)
364
+ # stop = DateTime.new(2001, 1, 9)
365
+ # date = Polars.date_range(start, stop, "2d")
366
+ # # =>
367
+ # # shape: (5,)
368
+ # # Series: '' [datetime[μs]]
369
+ # # [
370
+ # # 2001-01-01 00:00:00
371
+ # # 2001-01-03 00:00:00
372
+ # # 2001-01-05 00:00:00
373
+ # # 2001-01-07 00:00:00
374
+ # # 2001-01-09 00:00:00
375
+ # # ]
376
+ #
377
+ # @example
378
+ # date.dt.day
379
+ # # =>
380
+ # # shape: (5,)
381
+ # # Series: '' [i8]
382
+ # # [
383
+ # # 1
384
+ # # 3
385
+ # # 5
386
+ # # 7
387
+ # # 9
388
+ # # ]
389
+ def day
390
+ super
391
+ end
392
+
393
+ # Extract ordinal day from underlying date representation.
394
+ #
395
+ # Applies to Date and Datetime columns.
396
+ #
397
+ # Returns the day of year starting from 1.
398
+ # The return value ranges from 1 to 366. (The last day of year differs by years.)
399
+ #
400
+ # @return [Series]
401
+ #
402
+ # @example
403
+ # start = DateTime.new(2001, 1, 1)
404
+ # stop = DateTime.new(2001, 3, 1)
405
+ # date = Polars.date_range(start, stop, "1mo")
406
+ # # =>
407
+ # # shape: (3,)
408
+ # # Series: '' [datetime[μs]]
409
+ # # [
410
+ # # 2001-01-01 00:00:00
411
+ # # 2001-02-01 00:00:00
412
+ # # 2001-03-01 00:00:00
413
+ # # ]
414
+ #
415
+ # @example
416
+ # date.dt.ordinal_day
417
+ # # =>
418
+ # # shape: (3,)
419
+ # # Series: '' [i16]
420
+ # # [
421
+ # # 1
422
+ # # 32
423
+ # # 60
424
+ # # ]
425
+ def ordinal_day
426
+ super
427
+ end
428
+
429
+ # Extract the hour from the underlying DateTime representation.
430
+ #
431
+ # Applies to Datetime columns.
432
+ #
433
+ # Returns the hour number from 0 to 23.
434
+ #
435
+ # @return [Series]
436
+ #
437
+ # @example
438
+ # start = DateTime.new(2001, 1, 1)
439
+ # stop = DateTime.new(2001, 1, 1, 3)
440
+ # date = Polars.date_range(start, stop, "1h")
441
+ # # =>
442
+ # # shape: (4,)
443
+ # # Series: '' [datetime[μs]]
444
+ # # [
445
+ # # 2001-01-01 00:00:00
446
+ # # 2001-01-01 01:00:00
447
+ # # 2001-01-01 02:00:00
448
+ # # 2001-01-01 03:00:00
449
+ # # ]
450
+ #
451
+ # @example
452
+ # date.dt.hour
453
+ # # =>
454
+ # # shape: (4,)
455
+ # # Series: '' [i8]
456
+ # # [
457
+ # # 0
458
+ # # 1
459
+ # # 2
460
+ # # 3
461
+ # # ]
462
+ def hour
463
+ super
464
+ end
465
+
466
+ # Extract the minutes from the underlying DateTime representation.
467
+ #
468
+ # Applies to Datetime columns.
469
+ #
470
+ # Returns the minute number from 0 to 59.
471
+ #
472
+ # @return [Series]
473
+ #
474
+ # @example
475
+ # start = DateTime.new(2001, 1, 1)
476
+ # stop = DateTime.new(2001, 1, 1, 0, 4, 0)
477
+ # date = Polars.date_range(start, stop, "2m")
478
+ # # =>
479
+ # # shape: (3,)
480
+ # # Series: '' [datetime[μs]]
481
+ # # [
482
+ # # 2001-01-01 00:00:00
483
+ # # 2001-01-01 00:02:00
484
+ # # 2001-01-01 00:04:00
485
+ # # ]
486
+ #
487
+ # @example
488
+ # date.dt.minute
489
+ # # =>
490
+ # # shape: (3,)
491
+ # # Series: '' [i8]
492
+ # # [
493
+ # # 0
494
+ # # 2
495
+ # # 4
496
+ # # ]
497
+ def minute
498
+ super
499
+ end
500
+
501
+ # Extract seconds from underlying DateTime representation.
502
+ #
503
+ # Applies to Datetime columns.
504
+ #
505
+ # Returns the integer second number from 0 to 59, or a floating
506
+ # point number from 0 < 60 if `fractional: true` that includes
507
+ # any milli/micro/nanosecond component.
508
+ #
509
+ # @return [Series]
510
+ #
511
+ # @example
512
+ # start = DateTime.new(2001, 1, 1)
513
+ # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
514
+ # date = Polars.date_range(start, stop, "500ms")
515
+ # # =>
516
+ # # shape: (9,)
517
+ # # Series: '' [datetime[μs]]
518
+ # # [
519
+ # # 2001-01-01 00:00:00
520
+ # # 2001-01-01 00:00:00.500
521
+ # # 2001-01-01 00:00:01
522
+ # # 2001-01-01 00:00:01.500
523
+ # # 2001-01-01 00:00:02
524
+ # # 2001-01-01 00:00:02.500
525
+ # # 2001-01-01 00:00:03
526
+ # # 2001-01-01 00:00:03.500
527
+ # # 2001-01-01 00:00:04
528
+ # # ]
529
+ #
530
+ # @example
531
+ # date.dt.second
532
+ # # =>
533
+ # # shape: (9,)
534
+ # # Series: '' [i8]
535
+ # # [
536
+ # # 0
537
+ # # 0
538
+ # # 1
539
+ # # 1
540
+ # # 2
541
+ # # 2
542
+ # # 3
543
+ # # 3
544
+ # # 4
545
+ # # ]
546
+ #
547
+ # @example
548
+ # date.dt.second(fractional: true)
549
+ # # =>
550
+ # # shape: (9,)
551
+ # # Series: '' [f64]
552
+ # # [
553
+ # # 0.0
554
+ # # 0.5
555
+ # # 1.0
556
+ # # 1.5
557
+ # # 2.0
558
+ # # 2.5
559
+ # # 3.0
560
+ # # 3.5
561
+ # # 4.0
562
+ # # ]
563
+ def second(fractional: false)
564
+ super
565
+ end
566
+
567
+ # Extract the milliseconds from the underlying DateTime representation.
568
+ #
569
+ # Applies to Datetime columns.
570
+ #
571
+ # @return [Series]
572
+ #
573
+ # @example
574
+ # start = DateTime.new(2001, 1, 1)
575
+ # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
576
+ # date = Polars.date_range(start, stop, "500ms")
577
+ # # =>
578
+ # # shape: (9,)
579
+ # # Series: '' [datetime[μs]]
580
+ # # [
581
+ # # 2001-01-01 00:00:00
582
+ # # 2001-01-01 00:00:00.500
583
+ # # 2001-01-01 00:00:01
584
+ # # 2001-01-01 00:00:01.500
585
+ # # 2001-01-01 00:00:02
586
+ # # 2001-01-01 00:00:02.500
587
+ # # 2001-01-01 00:00:03
588
+ # # 2001-01-01 00:00:03.500
589
+ # # 2001-01-01 00:00:04
590
+ # # ]
591
+ #
592
+ # @example
593
+ # date.dt.millisecond
594
+ # # =>
595
+ # # shape: (9,)
596
+ # # Series: '' [i32]
597
+ # # [
598
+ # # 0
599
+ # # 500
600
+ # # 0
601
+ # # 500
602
+ # # 0
603
+ # # 500
604
+ # # 0
605
+ # # 500
606
+ # # 0
607
+ # # ]
608
+ def millisecond
609
+ super
610
+ end
611
+
612
+ # Extract the microseconds from the underlying DateTime representation.
613
+ #
614
+ # Applies to Datetime columns.
615
+ #
616
+ # @return [Series]
617
+ #
618
+ # @example
619
+ # start = DateTime.new(2001, 1, 1)
620
+ # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
621
+ # date = Polars.date_range(start, stop, "500ms")
622
+ # # =>
623
+ # # shape: (9,)
624
+ # # Series: '' [datetime[μs]]
625
+ # # [
626
+ # # 2001-01-01 00:00:00
627
+ # # 2001-01-01 00:00:00.500
628
+ # # 2001-01-01 00:00:01
629
+ # # 2001-01-01 00:00:01.500
630
+ # # 2001-01-01 00:00:02
631
+ # # 2001-01-01 00:00:02.500
632
+ # # 2001-01-01 00:00:03
633
+ # # 2001-01-01 00:00:03.500
634
+ # # 2001-01-01 00:00:04
635
+ # # ]
636
+ #
637
+ # @example
638
+ # date.dt.microsecond
639
+ # # =>
640
+ # # shape: (9,)
641
+ # # Series: '' [i32]
642
+ # # [
643
+ # # 0
644
+ # # 500000
645
+ # # 0
646
+ # # 500000
647
+ # # 0
648
+ # # 500000
649
+ # # 0
650
+ # # 500000
651
+ # # 0
652
+ # # ]
653
+ def microsecond
654
+ super
655
+ end
656
+
657
+ # Extract the nanoseconds from the underlying DateTime representation.
658
+ #
659
+ # Applies to Datetime columns.
660
+ #
661
+ # @return [Series]
662
+ #
663
+ # @example
664
+ # start = DateTime.new(2001, 1, 1)
665
+ # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
666
+ # date = Polars.date_range(start, stop, "500ms")
667
+ # # =>
668
+ # # shape: (9,)
669
+ # # Series: '' [datetime[μs]]
670
+ # # [
671
+ # # 2001-01-01 00:00:00
672
+ # # 2001-01-01 00:00:00.500
673
+ # # 2001-01-01 00:00:01
674
+ # # 2001-01-01 00:00:01.500
675
+ # # 2001-01-01 00:00:02
676
+ # # 2001-01-01 00:00:02.500
677
+ # # 2001-01-01 00:00:03
678
+ # # 2001-01-01 00:00:03.500
679
+ # # 2001-01-01 00:00:04
680
+ # # ]
681
+ #
682
+ # @example
683
+ # date.dt.nanosecond
684
+ # # =>
685
+ # # shape: (9,)
686
+ # # Series: '' [i32]
687
+ # # [
688
+ # # 0
689
+ # # 500000000
690
+ # # 0
691
+ # # 500000000
692
+ # # 0
693
+ # # 500000000
694
+ # # 0
695
+ # # 500000000
696
+ # # 0
697
+ # # ]
698
+ def nanosecond
699
+ super
700
+ end
701
+
702
+ # Return a timestamp in the given time unit.
703
+ #
704
+ # @param tu ["us", "ns", "ms"]
705
+ # Time unit.
706
+ #
707
+ # @return [Series]
708
+ #
709
+ # @example
710
+ # start = DateTime.new(2001, 1, 1)
711
+ # stop = DateTime.new(2001, 1, 3)
712
+ # date = Polars.date_range(start, stop, "1d")
713
+ # # =>
714
+ # # shape: (3,)
715
+ # # Series: '' [datetime[μs]]
716
+ # # [
717
+ # # 2001-01-01 00:00:00
718
+ # # 2001-01-02 00:00:00
719
+ # # 2001-01-03 00:00:00
720
+ # # ]
721
+ #
722
+ # @example
723
+ # date.dt.timestamp.alias("timestamp_us")
724
+ # # =>
725
+ # # shape: (3,)
726
+ # # Series: 'timestamp_us' [i64]
727
+ # # [
728
+ # # 978307200000000
729
+ # # 978393600000000
730
+ # # 978480000000000
731
+ # # ]
732
+ #
733
+ # @example
734
+ # date.dt.timestamp("ns").alias("timestamp_ns")
735
+ # # =>
736
+ # # shape: (3,)
737
+ # # Series: 'timestamp_ns' [i64]
738
+ # # [
739
+ # # 978307200000000000
740
+ # # 978393600000000000
741
+ # # 978480000000000000
742
+ # # ]
743
+ def timestamp(tu = "us")
744
+ super
745
+ end
746
+
747
+ # Get the time passed since the Unix EPOCH in the give time unit.
748
+ #
749
+ # @param tu ["us", "ns", "ms", "s", "d"]
750
+ # Time unit.
751
+ #
752
+ # @return [Series]
753
+ #
754
+ # @example
755
+ # start = DateTime.new(2001, 1, 1)
756
+ # stop = DateTime.new(2001, 1, 3)
757
+ # date = Polars.date_range(start, stop, "1d")
758
+ # # =>
759
+ # # shape: (3,)
760
+ # # Series: '' [datetime[μs]]
761
+ # # [
762
+ # # 2001-01-01 00:00:00
763
+ # # 2001-01-02 00:00:00
764
+ # # 2001-01-03 00:00:00
765
+ # # ]
766
+ #
767
+ # @example
768
+ # date.dt.epoch.alias("epoch_ns")
769
+ # # =>
770
+ # # shape: (3,)
771
+ # # Series: 'epoch_ns' [i64]
772
+ # # [
773
+ # # 978307200000000
774
+ # # 978393600000000
775
+ # # 978480000000000
776
+ # # ]
777
+ #
778
+ # @example
779
+ # date.dt.epoch("s").alias("epoch_s")
780
+ # # =>
781
+ # # shape: (3,)
782
+ # # Series: 'epoch_s' [i64]
783
+ # # [
784
+ # # 978307200
785
+ # # 978393600
786
+ # # 978480000
787
+ # # ]
788
+ def epoch(tu = "us")
789
+ super
790
+ end
791
+
792
+ # Set time unit a Series of dtype Datetime or Duration.
793
+ #
794
+ # This does not modify underlying data, and should be used to fix an incorrect
795
+ # time unit.
796
+ #
797
+ # @param tu ["ns", "us", "ms"]
798
+ # Time unit for the `Datetime` Series.
799
+ #
800
+ # @return [Series]
801
+ #
802
+ # @example
803
+ # start = DateTime.new(2001, 1, 1)
804
+ # stop = DateTime.new(2001, 1, 3)
805
+ # date = Polars.date_range(start, stop, "1d", time_unit: "ns")
806
+ # # =>
807
+ # # shape: (3,)
808
+ # # Series: '' [datetime[ns]]
809
+ # # [
810
+ # # 2001-01-01 00:00:00
811
+ # # 2001-01-02 00:00:00
812
+ # # 2001-01-03 00:00:00
813
+ # # ]
814
+ #
815
+ # @example
816
+ # date.dt.with_time_unit("us").alias("tu_us")
817
+ # # =>
818
+ # # shape: (3,)
819
+ # # Series: 'tu_us' [datetime[μs]]
820
+ # # [
821
+ # # +32971-04-28 00:00:00
822
+ # # +32974-01-22 00:00:00
823
+ # # +32976-10-18 00:00:00
824
+ # # ]
825
+ def with_time_unit(tu)
826
+ super
827
+ end
828
+
829
+ # Cast the underlying data to another time unit. This may lose precision.
830
+ #
831
+ # @param tu ["ns", "us", "ms"]
832
+ # Time unit for the `Datetime` Series.
833
+ #
834
+ # @return [Series]
835
+ #
836
+ # @example
837
+ # start = DateTime.new(2001, 1, 1)
838
+ # stop = DateTime.new(2001, 1, 3)
839
+ # date = Polars.date_range(start, stop, "1d")
840
+ # # =>
841
+ # # shape: (3,)
842
+ # # Series: '' [datetime[μs]]
843
+ # # [
844
+ # # 2001-01-01 00:00:00
845
+ # # 2001-01-02 00:00:00
846
+ # # 2001-01-03 00:00:00
847
+ # # ]
848
+ #
849
+ # @example
850
+ # date.dt.cast_time_unit("ms").alias("tu_ms")
851
+ # # =>
852
+ # # shape: (3,)
853
+ # # Series: 'tu_ms' [datetime[ms]]
854
+ # # [
855
+ # # 2001-01-01 00:00:00
856
+ # # 2001-01-02 00:00:00
857
+ # # 2001-01-03 00:00:00
858
+ # # ]
859
+ #
860
+ # @example
861
+ # date.dt.cast_time_unit("ns").alias("tu_ns")
862
+ # # =>
863
+ # # shape: (3,)
864
+ # # Series: 'tu_ns' [datetime[ns]]
865
+ # # [
866
+ # # 2001-01-01 00:00:00
867
+ # # 2001-01-02 00:00:00
868
+ # # 2001-01-03 00:00:00
869
+ # # ]
870
+ def cast_time_unit(tu)
871
+ super
872
+ end
873
+
874
+ # Set time zone a Series of type Datetime.
875
+ #
876
+ # @param tz [String]
877
+ # Time zone for the `Datetime` Series.
878
+ #
879
+ # @return [Series]
880
+ #
881
+ # @example
882
+ # start = DateTime.new(2020, 3, 1)
883
+ # stop = DateTime.new(2020, 5, 1)
884
+ # date = Polars.date_range(start, stop, "1mo", time_zone: "UTC")
885
+ # # =>
886
+ # # shape: (3,)
887
+ # # Series: '' [datetime[μs, UTC]]
888
+ # # [
889
+ # # 2020-03-01 00:00:00 UTC
890
+ # # 2020-04-01 00:00:00 UTC
891
+ # # 2020-05-01 00:00:00 UTC
892
+ # # ]
893
+ #
894
+ # @example
895
+ # date.dt.convert_time_zone("Europe/London").alias("London")
896
+ # # =>
897
+ # # shape: (3,)
898
+ # # Series: 'London' [datetime[μs, Europe/London]]
899
+ # # [
900
+ # # 2020-03-01 00:00:00 GMT
901
+ # # 2020-04-01 01:00:00 BST
902
+ # # 2020-05-01 01:00:00 BST
903
+ # # ]
904
+ def convert_time_zone(tz)
905
+ super
906
+ end
907
+
908
+ # Cast time zone for a Series of type Datetime.
909
+ #
910
+ # Different from `with_time_zone`, this will also modify
911
+ # the underlying timestamp.
912
+ #
913
+ # @param time_zone [String]
914
+ # Time zone for the `Datetime` Series. Pass `nil` to unset time zone.
915
+ # @param use_earliest [Boolean]
916
+ # Determine how to deal with ambiguous datetimes.
917
+ # @param ambiguous [String]
918
+ # Determine how to deal with ambiguous datetimes.
919
+ # @param non_existent [String]
920
+ # Determine how to deal with non-existent datetimes.
921
+ #
922
+ # @return [Series]
923
+ #
924
+ # @example
925
+ # start = DateTime.new(2020, 3, 1)
926
+ # stop = DateTime.new(2020, 5, 1)
927
+ # date = Polars.date_range(start, stop, "1mo", time_zone: "UTC")
928
+ # # =>
929
+ # # shape: (3,)
930
+ # # Series: '' [datetime[μs, UTC]]
931
+ # # [
932
+ # # 2020-03-01 00:00:00 UTC
933
+ # # 2020-04-01 00:00:00 UTC
934
+ # # 2020-05-01 00:00:00 UTC
935
+ # # ]
936
+ #
937
+ # @example
938
+ # date.dt.epoch("s")
939
+ # # =>
940
+ # # shape: (3,)
941
+ # # Series: '' [i64]
942
+ # # [
943
+ # # 1583020800
944
+ # # 1585699200
945
+ # # 1588291200
946
+ # # ]
947
+ #
948
+ # @example
949
+ # date = date.dt.convert_time_zone("Europe/London").alias("London")
950
+ # # =>
951
+ # # shape: (3,)
952
+ # # Series: 'London' [datetime[μs, Europe/London]]
953
+ # # [
954
+ # # 2020-03-01 00:00:00 GMT
955
+ # # 2020-04-01 01:00:00 BST
956
+ # # 2020-05-01 01:00:00 BST
957
+ # # ]
958
+ #
959
+ # @example Timestamps have not changed after convert_time_zone
960
+ # date.dt.epoch("s")
961
+ # # =>
962
+ # # shape: (3,)
963
+ # # Series: 'London' [i64]
964
+ # # [
965
+ # # 1583020800
966
+ # # 1585699200
967
+ # # 1588291200
968
+ # # ]
969
+ #
970
+ # @example
971
+ # date = date.dt.replace_time_zone("America/New_York").alias("NYC")
972
+ # # =>
973
+ # # shape: (3,)
974
+ # # Series: 'NYC' [datetime[μs, America/New_York]]
975
+ # # [
976
+ # # 2020-03-01 00:00:00 EST
977
+ # # 2020-04-01 01:00:00 EDT
978
+ # # 2020-05-01 01:00:00 EDT
979
+ # # ]
980
+ #
981
+ # @example Timestamps have changed after replace_time_zone
982
+ # date.dt.epoch("s")
983
+ # # =>
984
+ # # shape: (3,)
985
+ # # Series: 'NYC' [i64]
986
+ # # [
987
+ # # 1583038800
988
+ # # 1585717200
989
+ # # 1588309200
990
+ # # ]
991
+ def replace_time_zone(time_zone, use_earliest: nil, ambiguous: "raise", non_existent: "raise")
992
+ super
993
+ end
994
+
995
+ # Localize tz-naive Datetime Series to tz-aware Datetime Series.
996
+ #
997
+ # This method takes a naive Datetime Series and makes this time zone aware.
998
+ # It does not move the time to another time zone.
999
+ #
1000
+ # @param tz [String]
1001
+ # Time zone for the `Datetime` Series.
1002
+ #
1003
+ # @return [Series]
1004
+ def tz_localize(tz)
1005
+ super
1006
+ end
1007
+
1008
+ # Extract the days from a Duration type.
1009
+ #
1010
+ # @return [Series]
1011
+ #
1012
+ # @example
1013
+ # date = Polars.date_range(DateTime.new(2020, 3, 1), DateTime.new(2020, 5, 1), "1mo")
1014
+ # # =>
1015
+ # # shape: (3,)
1016
+ # # Series: '' [datetime[μs]]
1017
+ # # [
1018
+ # # 2020-03-01 00:00:00
1019
+ # # 2020-04-01 00:00:00
1020
+ # # 2020-05-01 00:00:00
1021
+ # # ]
1022
+ #
1023
+ # @example
1024
+ # date.diff.dt.days
1025
+ # # =>
1026
+ # # shape: (3,)
1027
+ # # Series: '' [i64]
1028
+ # # [
1029
+ # # null
1030
+ # # 31
1031
+ # # 30
1032
+ # # ]
1033
+ def days
1034
+ super
1035
+ end
1036
+
1037
+ # Extract the hours from a Duration type.
1038
+ #
1039
+ # @return [Series]
1040
+ #
1041
+ # @example
1042
+ # date = Polars.date_range(DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 4), "1d")
1043
+ # # =>
1044
+ # # shape: (4,)
1045
+ # # Series: '' [datetime[μs]]
1046
+ # # [
1047
+ # # 2020-01-01 00:00:00
1048
+ # # 2020-01-02 00:00:00
1049
+ # # 2020-01-03 00:00:00
1050
+ # # 2020-01-04 00:00:00
1051
+ # # ]
1052
+ #
1053
+ # @example
1054
+ # date.diff.dt.hours
1055
+ # # =>
1056
+ # # shape: (4,)
1057
+ # # Series: '' [i64]
1058
+ # # [
1059
+ # # null
1060
+ # # 24
1061
+ # # 24
1062
+ # # 24
1063
+ # # ]
1064
+ def hours
1065
+ super
1066
+ end
1067
+
1068
+ # Extract the minutes from a Duration type.
1069
+ #
1070
+ # @return [Series]
1071
+ #
1072
+ # @example
1073
+ # date = Polars.date_range(DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 4), "1d")
1074
+ # # =>
1075
+ # # shape: (4,)
1076
+ # # Series: '' [datetime[μs]]
1077
+ # # [
1078
+ # # 2020-01-01 00:00:00
1079
+ # # 2020-01-02 00:00:00
1080
+ # # 2020-01-03 00:00:00
1081
+ # # 2020-01-04 00:00:00
1082
+ # # ]
1083
+ #
1084
+ # @example
1085
+ # date.diff.dt.minutes
1086
+ # # =>
1087
+ # # shape: (4,)
1088
+ # # Series: '' [i64]
1089
+ # # [
1090
+ # # null
1091
+ # # 1440
1092
+ # # 1440
1093
+ # # 1440
1094
+ # # ]
1095
+ def minutes
1096
+ super
1097
+ end
1098
+
1099
+ # Extract the seconds from a Duration type.
1100
+ #
1101
+ # @return [Series]
1102
+ #
1103
+ # @example
1104
+ # date = Polars.date_range(
1105
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 4, 0), "1m"
1106
+ # )
1107
+ # # =>
1108
+ # # shape: (5,)
1109
+ # # Series: '' [datetime[μs]]
1110
+ # # [
1111
+ # # 2020-01-01 00:00:00
1112
+ # # 2020-01-01 00:01:00
1113
+ # # 2020-01-01 00:02:00
1114
+ # # 2020-01-01 00:03:00
1115
+ # # 2020-01-01 00:04:00
1116
+ # # ]
1117
+ #
1118
+ # @example
1119
+ # date.diff.dt.seconds
1120
+ # # =>
1121
+ # # shape: (5,)
1122
+ # # Series: '' [i64]
1123
+ # # [
1124
+ # # null
1125
+ # # 60
1126
+ # # 60
1127
+ # # 60
1128
+ # # 60
1129
+ # # ]
1130
+ def seconds
1131
+ super
1132
+ end
1133
+
1134
+ # Extract the milliseconds from a Duration type.
1135
+ #
1136
+ # @return [Series]
1137
+ #
1138
+ # @example
1139
+ # date = Polars.date_range(
1140
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms"
1141
+ # )[0..2]
1142
+ # # =>
1143
+ # # shape: (3,)
1144
+ # # Series: '' [datetime[μs]]
1145
+ # # [
1146
+ # # 2020-01-01 00:00:00
1147
+ # # 2020-01-01 00:00:00.001
1148
+ # # 2020-01-01 00:00:00.002
1149
+ # # ]
1150
+ #
1151
+ # @example
1152
+ # date.diff.dt.milliseconds
1153
+ # # =>
1154
+ # # shape: (3,)
1155
+ # # Series: '' [i64]
1156
+ # # [
1157
+ # # null
1158
+ # # 1
1159
+ # # 1
1160
+ # # ]
1161
+ def milliseconds
1162
+ super
1163
+ end
1164
+
1165
+ # Extract the microseconds from a Duration type.
1166
+ #
1167
+ # @return [Series]
1168
+ #
1169
+ # @example
1170
+ # date = Polars.date_range(
1171
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms"
1172
+ # )[0..2]
1173
+ # # =>
1174
+ # # shape: (3,)
1175
+ # # Series: '' [datetime[μs]]
1176
+ # # [
1177
+ # # 2020-01-01 00:00:00
1178
+ # # 2020-01-01 00:00:00.001
1179
+ # # 2020-01-01 00:00:00.002
1180
+ # # ]
1181
+ #
1182
+ # @example
1183
+ # date.diff.dt.microseconds
1184
+ # # =>
1185
+ # # shape: (3,)
1186
+ # # Series: '' [i64]
1187
+ # # [
1188
+ # # null
1189
+ # # 1000
1190
+ # # 1000
1191
+ # # ]
1192
+ def microseconds
1193
+ super
1194
+ end
1195
+
1196
+ # Extract the nanoseconds from a Duration type.
1197
+ #
1198
+ # @return [Series]
1199
+ #
1200
+ # @example
1201
+ # date = Polars.date_range(
1202
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms"
1203
+ # )[0..2]
1204
+ # # =>
1205
+ # # shape: (3,)
1206
+ # # Series: '' [datetime[μs]]
1207
+ # # [
1208
+ # # 2020-01-01 00:00:00
1209
+ # # 2020-01-01 00:00:00.001
1210
+ # # 2020-01-01 00:00:00.002
1211
+ # # ]
1212
+ #
1213
+ # @example
1214
+ # date.diff.dt.nanoseconds
1215
+ # # =>
1216
+ # # shape: (3,)
1217
+ # # Series: '' [i64]
1218
+ # # [
1219
+ # # null
1220
+ # # 1000000
1221
+ # # 1000000
1222
+ # # ]
1223
+ def nanoseconds
1224
+ super
1225
+ end
1226
+
1227
+ # Offset this date by a relative time offset.
1228
+ #
1229
+ # This differs from `Polars.col("foo") + timedelta` in that it can
1230
+ # take months and leap years into account. Note that only a single minus
1231
+ # sign is allowed in the `by` string, as the first character.
1232
+ #
1233
+ # @param by [String]
1234
+ # The offset is dictated by the following string language:
1235
+ #
1236
+ # - 1ns (1 nanosecond)
1237
+ # - 1us (1 microsecond)
1238
+ # - 1ms (1 millisecond)
1239
+ # - 1s (1 second)
1240
+ # - 1m (1 minute)
1241
+ # - 1h (1 hour)
1242
+ # - 1d (1 day)
1243
+ # - 1w (1 week)
1244
+ # - 1mo (1 calendar month)
1245
+ # - 1y (1 calendar year)
1246
+ # - 1i (1 index count)
1247
+ #
1248
+ # @return [Series]
1249
+ #
1250
+ # @example
1251
+ # dates = Polars.date_range(DateTime.new(2000, 1, 1), DateTime.new(2005, 1, 1), "1y")
1252
+ # # =>
1253
+ # # shape: (6,)
1254
+ # # Series: '' [datetime[μs]]
1255
+ # # [
1256
+ # # 2000-01-01 00:00:00
1257
+ # # 2001-01-01 00:00:00
1258
+ # # 2002-01-01 00:00:00
1259
+ # # 2003-01-01 00:00:00
1260
+ # # 2004-01-01 00:00:00
1261
+ # # 2005-01-01 00:00:00
1262
+ # # ]
1263
+ #
1264
+ # @example
1265
+ # dates.dt.offset_by("1y").alias("date_plus_1y")
1266
+ # # =>
1267
+ # # shape: (6,)
1268
+ # # Series: 'date_plus_1y' [datetime[μs]]
1269
+ # # [
1270
+ # # 2001-01-01 00:00:00
1271
+ # # 2002-01-01 00:00:00
1272
+ # # 2003-01-01 00:00:00
1273
+ # # 2004-01-01 00:00:00
1274
+ # # 2005-01-01 00:00:00
1275
+ # # 2006-01-01 00:00:00
1276
+ # # ]
1277
+ #
1278
+ # @example
1279
+ # dates.dt.offset_by("-1y2mo").alias("date_minus_1y_2mon")
1280
+ # # =>
1281
+ # # shape: (6,)
1282
+ # # Series: 'date_minus_1y_2mon' [datetime[μs]]
1283
+ # # [
1284
+ # # 1998-11-01 00:00:00
1285
+ # # 1999-11-01 00:00:00
1286
+ # # 2000-11-01 00:00:00
1287
+ # # 2001-11-01 00:00:00
1288
+ # # 2002-11-01 00:00:00
1289
+ # # 2003-11-01 00:00:00
1290
+ # # ]
1291
+ def offset_by(by)
1292
+ super
1293
+ end
1294
+
1295
+ # Divide the date/ datetime range into buckets.
1296
+ #
1297
+ # Each date/datetime is mapped to the start of its bucket.
1298
+ #
1299
+ # The `every` and `offset` argument are created with the
1300
+ # the following string language:
1301
+ #
1302
+ # 1ns # 1 nanosecond
1303
+ # 1us # 1 microsecond
1304
+ # 1ms # 1 millisecond
1305
+ # 1s # 1 second
1306
+ # 1m # 1 minute
1307
+ # 1h # 1 hour
1308
+ # 1d # 1 day
1309
+ # 1w # 1 week
1310
+ # 1mo # 1 calendar month
1311
+ # 1y # 1 calendar year
1312
+ #
1313
+ # 3d12h4m25s # 3 days, 12 hours, 4 minutes, and 25 seconds
1314
+ #
1315
+ # @param every [String]
1316
+ # Every interval start and period length.
1317
+ # @param offset [String]
1318
+ # Offset the window.
1319
+ #
1320
+ # @return [Series]
1321
+ #
1322
+ # @example
1323
+ # start = DateTime.new(2001, 1, 1)
1324
+ # stop = DateTime.new(2001, 1, 2)
1325
+ # s = Polars.date_range(start, stop, "165m", name: "dates")
1326
+ # # =>
1327
+ # # shape: (9,)
1328
+ # # Series: 'dates' [datetime[μs]]
1329
+ # # [
1330
+ # # 2001-01-01 00:00:00
1331
+ # # 2001-01-01 02:45:00
1332
+ # # 2001-01-01 05:30:00
1333
+ # # 2001-01-01 08:15:00
1334
+ # # 2001-01-01 11:00:00
1335
+ # # 2001-01-01 13:45:00
1336
+ # # 2001-01-01 16:30:00
1337
+ # # 2001-01-01 19:15:00
1338
+ # # 2001-01-01 22:00:00
1339
+ # # ]
1340
+ #
1341
+ # @example
1342
+ # s.dt.truncate("1h")
1343
+ # # =>
1344
+ # # shape: (9,)
1345
+ # # Series: 'dates' [datetime[μs]]
1346
+ # # [
1347
+ # # 2001-01-01 00:00:00
1348
+ # # 2001-01-01 02:00:00
1349
+ # # 2001-01-01 05:00:00
1350
+ # # 2001-01-01 08:00:00
1351
+ # # 2001-01-01 11:00:00
1352
+ # # 2001-01-01 13:00:00
1353
+ # # 2001-01-01 16:00:00
1354
+ # # 2001-01-01 19:00:00
1355
+ # # 2001-01-01 22:00:00
1356
+ # # ]
1357
+ #
1358
+ # @example
1359
+ # start = DateTime.new(2001, 1, 1)
1360
+ # stop = DateTime.new(2001, 1, 1, 1)
1361
+ # s = Polars.date_range(start, stop, "10m", name: "dates")
1362
+ # # =>
1363
+ # # shape: (7,)
1364
+ # # Series: 'dates' [datetime[μs]]
1365
+ # # [
1366
+ # # 2001-01-01 00:00:00
1367
+ # # 2001-01-01 00:10:00
1368
+ # # 2001-01-01 00:20:00
1369
+ # # 2001-01-01 00:30:00
1370
+ # # 2001-01-01 00:40:00
1371
+ # # 2001-01-01 00:50:00
1372
+ # # 2001-01-01 01:00:00
1373
+ # # ]
1374
+ #
1375
+ # @example
1376
+ # s.dt.truncate("30m")
1377
+ # # =>
1378
+ # # shape: (7,)
1379
+ # # Series: 'dates' [datetime[μs]]
1380
+ # # [
1381
+ # # 2001-01-01 00:00:00
1382
+ # # 2001-01-01 00:00:00
1383
+ # # 2001-01-01 00:00:00
1384
+ # # 2001-01-01 00:30:00
1385
+ # # 2001-01-01 00:30:00
1386
+ # # 2001-01-01 00:30:00
1387
+ # # 2001-01-01 01:00:00
1388
+ # # ]
1389
+ def truncate(every, offset: nil, use_earliest: nil)
1390
+ super
1391
+ end
1392
+
1393
+ # Divide the date/ datetime range into buckets.
1394
+ #
1395
+ # Each date/datetime in the first half of the interval
1396
+ # is mapped to the start of its bucket.
1397
+ # Each date/datetime in the seconod half of the interval
1398
+ # is mapped to the end of its bucket.
1399
+ #
1400
+ # The `every` and `offset` argument are created with the
1401
+ # the following string language:
1402
+ #
1403
+ # 1ns # 1 nanosecond
1404
+ # 1us # 1 microsecond
1405
+ # 1ms # 1 millisecond
1406
+ # 1s # 1 second
1407
+ # 1m # 1 minute
1408
+ # 1h # 1 hour
1409
+ # 1d # 1 day
1410
+ # 1w # 1 week
1411
+ # 1mo # 1 calendar month
1412
+ # 1y # 1 calendar year
1413
+ #
1414
+ # 3d12h4m25s # 3 days, 12 hours, 4 minutes, and 25 seconds
1415
+ #
1416
+ # @param every [String]
1417
+ # Every interval start and period length.
1418
+ # @param offset [String]
1419
+ # Offset the window.
1420
+ #
1421
+ # @return [Series]
1422
+ #
1423
+ # @note
1424
+ # This functionality is currently experimental and may
1425
+ # change without it being considered a breaking change.
1426
+ #
1427
+ # @example
1428
+ # start = DateTime.new(2001, 1, 1)
1429
+ # stop = DateTime.new(2001, 1, 2)
1430
+ # s = Polars.date_range(start, stop, "165m", name: "dates")
1431
+ # # =>
1432
+ # # shape: (9,)
1433
+ # # Series: 'dates' [datetime[μs]]
1434
+ # # [
1435
+ # # 2001-01-01 00:00:00
1436
+ # # 2001-01-01 02:45:00
1437
+ # # 2001-01-01 05:30:00
1438
+ # # 2001-01-01 08:15:00
1439
+ # # 2001-01-01 11:00:00
1440
+ # # 2001-01-01 13:45:00
1441
+ # # 2001-01-01 16:30:00
1442
+ # # 2001-01-01 19:15:00
1443
+ # # 2001-01-01 22:00:00
1444
+ # # ]
1445
+ #
1446
+ # @example
1447
+ # s.dt.round("1h")
1448
+ # # =>
1449
+ # # shape: (9,)
1450
+ # # Series: 'dates' [datetime[μs]]
1451
+ # # [
1452
+ # # 2001-01-01 00:00:00
1453
+ # # 2001-01-01 03:00:00
1454
+ # # 2001-01-01 06:00:00
1455
+ # # 2001-01-01 08:00:00
1456
+ # # 2001-01-01 11:00:00
1457
+ # # 2001-01-01 14:00:00
1458
+ # # 2001-01-01 17:00:00
1459
+ # # 2001-01-01 19:00:00
1460
+ # # 2001-01-01 22:00:00
1461
+ # # ]
1462
+ #
1463
+ # @example
1464
+ # start = DateTime.new(2001, 1, 1)
1465
+ # stop = DateTime.new(2001, 1, 1, 1)
1466
+ # s = Polars.date_range(start, stop, "10m", name: "dates")
1467
+ # s.dt.round("30m")
1468
+ # # =>
1469
+ # # shape: (7,)
1470
+ # # Series: 'dates' [datetime[μs]]
1471
+ # # [
1472
+ # # 2001-01-01 00:00:00
1473
+ # # 2001-01-01 00:00:00
1474
+ # # 2001-01-01 00:30:00
1475
+ # # 2001-01-01 00:30:00
1476
+ # # 2001-01-01 00:30:00
1477
+ # # 2001-01-01 01:00:00
1478
+ # # 2001-01-01 01:00:00
1479
+ # # ]
1480
+ def round(every, offset: nil)
1481
+ super
1482
+ end
1483
+ end
1484
+ end