polars-df 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/Cargo.lock +360 -361
  4. data/ext/polars/Cargo.toml +10 -7
  5. data/ext/polars/src/batched_csv.rs +1 -1
  6. data/ext/polars/src/conversion/any_value.rs +261 -0
  7. data/ext/polars/src/conversion/chunked_array.rs +4 -4
  8. data/ext/polars/src/conversion/mod.rs +51 -10
  9. data/ext/polars/src/dataframe/construction.rs +6 -8
  10. data/ext/polars/src/dataframe/general.rs +19 -29
  11. data/ext/polars/src/dataframe/io.rs +43 -33
  12. data/ext/polars/src/error.rs +26 -4
  13. data/ext/polars/src/expr/categorical.rs +0 -10
  14. data/ext/polars/src/expr/datetime.rs +4 -12
  15. data/ext/polars/src/expr/general.rs +123 -110
  16. data/ext/polars/src/expr/mod.rs +2 -2
  17. data/ext/polars/src/expr/rolling.rs +17 -9
  18. data/ext/polars/src/expr/string.rs +2 -6
  19. data/ext/polars/src/functions/eager.rs +10 -10
  20. data/ext/polars/src/functions/lazy.rs +21 -21
  21. data/ext/polars/src/functions/range.rs +6 -12
  22. data/ext/polars/src/interop/numo/to_numo_series.rs +2 -1
  23. data/ext/polars/src/lazyframe/mod.rs +81 -98
  24. data/ext/polars/src/lib.rs +55 -45
  25. data/ext/polars/src/map/dataframe.rs +2 -2
  26. data/ext/polars/src/rb_modules.rs +25 -1
  27. data/ext/polars/src/series/aggregation.rs +4 -2
  28. data/ext/polars/src/series/arithmetic.rs +21 -11
  29. data/ext/polars/src/series/construction.rs +56 -38
  30. data/ext/polars/src/series/export.rs +1 -1
  31. data/ext/polars/src/series/mod.rs +31 -10
  32. data/ext/polars/src/sql.rs +3 -1
  33. data/lib/polars/array_expr.rb +4 -4
  34. data/lib/polars/batched_csv_reader.rb +2 -2
  35. data/lib/polars/cat_expr.rb +0 -36
  36. data/lib/polars/cat_name_space.rb +0 -37
  37. data/lib/polars/data_frame.rb +93 -101
  38. data/lib/polars/data_types.rb +1 -1
  39. data/lib/polars/date_time_expr.rb +525 -573
  40. data/lib/polars/date_time_name_space.rb +263 -464
  41. data/lib/polars/dynamic_group_by.rb +3 -3
  42. data/lib/polars/exceptions.rb +3 -0
  43. data/lib/polars/expr.rb +367 -330
  44. data/lib/polars/expr_dispatch.rb +1 -1
  45. data/lib/polars/functions/aggregation/horizontal.rb +8 -8
  46. data/lib/polars/functions/as_datatype.rb +63 -40
  47. data/lib/polars/functions/lazy.rb +63 -14
  48. data/lib/polars/functions/lit.rb +1 -1
  49. data/lib/polars/functions/range/date_range.rb +18 -77
  50. data/lib/polars/functions/range/datetime_range.rb +4 -4
  51. data/lib/polars/functions/range/int_range.rb +2 -2
  52. data/lib/polars/functions/range/time_range.rb +4 -4
  53. data/lib/polars/functions/repeat.rb +1 -1
  54. data/lib/polars/functions/whenthen.rb +1 -1
  55. data/lib/polars/io/csv.rb +8 -8
  56. data/lib/polars/io/ipc.rb +3 -3
  57. data/lib/polars/io/json.rb +13 -2
  58. data/lib/polars/io/ndjson.rb +15 -4
  59. data/lib/polars/io/parquet.rb +5 -4
  60. data/lib/polars/lazy_frame.rb +120 -106
  61. data/lib/polars/lazy_group_by.rb +1 -1
  62. data/lib/polars/list_expr.rb +11 -11
  63. data/lib/polars/list_name_space.rb +5 -1
  64. data/lib/polars/rolling_group_by.rb +5 -7
  65. data/lib/polars/series.rb +105 -189
  66. data/lib/polars/string_expr.rb +42 -67
  67. data/lib/polars/string_name_space.rb +5 -4
  68. data/lib/polars/testing.rb +2 -2
  69. data/lib/polars/utils/constants.rb +9 -0
  70. data/lib/polars/utils/convert.rb +97 -0
  71. data/lib/polars/utils/parse.rb +89 -0
  72. data/lib/polars/utils/various.rb +76 -0
  73. data/lib/polars/utils/wrap.rb +19 -0
  74. data/lib/polars/utils.rb +4 -330
  75. data/lib/polars/version.rb +1 -1
  76. data/lib/polars/whenthen.rb +6 -6
  77. data/lib/polars.rb +11 -0
  78. metadata +9 -4
  79. data/ext/polars/src/conversion/anyvalue.rs +0 -186
@@ -23,9 +23,9 @@ module Polars
23
23
  # @return [Object]
24
24
  #
25
25
  # @example
26
- # s = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
26
+ # s = Polars::Series.new([Date.new(2001, 1, 1), Date.new(2001, 1, 2), Date.new(2001, 1, 3)])
27
27
  # s.dt.min
28
- # # => 2001-01-01 00:00:00 UTC
28
+ # # => Mon, 01 Jan 2001
29
29
  def min
30
30
  Utils.wrap_s(_s).min
31
31
  end
@@ -35,9 +35,9 @@ module Polars
35
35
  # @return [Object]
36
36
  #
37
37
  # @example
38
- # s = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
38
+ # s = Polars::Series.new([Date.new(2001, 1, 1), Date.new(2001, 1, 2), Date.new(2001, 1, 3)])
39
39
  # s.dt.max
40
- # # => 2001-01-03 00:00:00 UTC
40
+ # # => Wed, 03 Jan 2001
41
41
  def max
42
42
  Utils.wrap_s(_s).max
43
43
  end
@@ -47,10 +47,12 @@ module Polars
47
47
  # @return [Object]
48
48
  #
49
49
  # @example
50
- # date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
50
+ # date = Polars.datetime_range(
51
+ # DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d", eager: true
52
+ # ).alias("datetime")
51
53
  # # =>
52
54
  # # shape: (3,)
53
- # # Series: '' [datetime[μs]]
55
+ # # Series: 'datetime' [datetime[ns]]
54
56
  # # [
55
57
  # # 2001-01-01 00:00:00
56
58
  # # 2001-01-02 00:00:00
@@ -61,18 +63,7 @@ module Polars
61
63
  # date.dt.median
62
64
  # # => 2001-01-02 00:00:00 UTC
63
65
  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
- elsif [Datetime, Duration, Time].include?(s.dtype)
70
- return out
71
- else
72
- return Utils._to_ruby_datetime(out.to_i, s.time_unit)
73
- end
74
- end
75
- nil
66
+ _s.median
76
67
  end
77
68
 
78
69
  # Return mean as Ruby object.
@@ -80,64 +71,69 @@ module Polars
80
71
  # @return [Object]
81
72
  #
82
73
  # @example
83
- # date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
84
- # # =>
85
- # # shape: (3,)
86
- # # Series: '' [datetime[μs]]
87
- # # [
88
- # # 2001-01-01 00:00:00
89
- # # 2001-01-02 00:00:00
90
- # # 2001-01-03 00:00:00
91
- # # ]
74
+ # s = Polars::Series.new([Date.new(2001, 1, 1), Date.new(2001, 1, 2)])
75
+ # s.dt.mean
76
+ # # => 2001-01-01 12:00:00 UTC
92
77
  #
93
78
  # @example
94
- # date.dt.mean
79
+ # s = Polars::Series.new(
80
+ # [DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 2), DateTime.new(2001, 1, 3)]
81
+ # )
82
+ # s.dt.mean
95
83
  # # => 2001-01-02 00:00:00 UTC
96
84
  def mean
97
- s = Utils.wrap_s(_s)
98
- out = s.mean
99
- if !out.nil?
100
- if s.dtype == Date
101
- return Utils._to_ruby_date(out.to_i)
102
- elsif [Datetime, Duration, Time].include?(s.dtype)
103
- return out
104
- else
105
- return Utils._to_ruby_datetime(out.to_i, s.time_unit)
106
- end
107
- end
108
- nil
85
+ _s.mean
109
86
  end
110
87
 
111
- # Format Date/datetime with a formatting rule.
88
+ # Convert a Date/Time/Datetime column into a String column with the given format.
112
89
  #
113
- # See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
90
+ # Similar to `cast(Polars::String)`, but this method allows you to customize the
91
+ # formatting of the resulting string.
92
+ #
93
+ # @param format [String]
94
+ # Format to use, refer to the `chrono strftime documentation
95
+ # <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
96
+ # for specification. Example: `"%y-%m-%d"`.
114
97
  #
115
98
  # @return [Series]
116
99
  #
117
100
  # @example
118
- # start = DateTime.new(2001, 1, 1)
119
- # stop = DateTime.new(2001, 1, 4)
120
- # date = Polars.date_range(start, stop, "1d")
101
+ # s = Polars::Series.new(
102
+ # "datetime",
103
+ # [DateTime.new(2020, 3, 1), DateTime.new(2020, 4, 1), DateTime.new(2020, 5, 1)],
104
+ # )
105
+ # s.dt.to_string("%Y/%m/%d")
121
106
  # # =>
122
- # # shape: (4,)
123
- # # Series: '' [datetime[μs]]
107
+ # # shape: (3,)
108
+ # # Series: 'datetime' [str]
124
109
  # # [
125
- # # 2001-01-01 00:00:00
126
- # # 2001-01-02 00:00:00
127
- # # 2001-01-03 00:00:00
128
- # # 2001-01-04 00:00:00
110
+ # # "2020/03/01"
111
+ # # "2020/04/01"
112
+ # # "2020/05/01"
129
113
  # # ]
114
+ def to_string(format)
115
+ super
116
+ end
117
+
118
+ # Format Date/datetime with a formatting rule.
119
+ #
120
+ # See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
121
+ #
122
+ # @return [Series]
130
123
  #
131
124
  # @example
132
- # date.dt.strftime("%Y-%m-%d")
125
+ # s = Polars::Series.new(
126
+ # "datetime",
127
+ # [DateTime.new(2020, 3, 1), DateTime.new(2020, 4, 1), DateTime.new(2020, 5, 1)]
128
+ # )
129
+ # s.dt.strftime("%Y/%m/%d")
133
130
  # # =>
134
- # # shape: (4,)
135
- # # Series: '' [str]
131
+ # # shape: (3,)
132
+ # # Series: 'datetime' [str]
136
133
  # # [
137
- # # "2001-01-01"
138
- # # "2001-01-02"
139
- # # "2001-01-03"
140
- # # "2001-01-04"
134
+ # # "2020/03/01"
135
+ # # "2020/04/01"
136
+ # # "2020/05/01"
141
137
  # # ]
142
138
  def strftime(fmt)
143
139
  super
@@ -152,22 +148,11 @@ module Polars
152
148
  # @return [Series]
153
149
  #
154
150
  # @example
155
- # start = DateTime.new(2001, 1, 1)
156
- # stop = DateTime.new(2002, 1, 1)
157
- # date = Polars.date_range(start, stop, "1y")
158
- # # =>
159
- # # shape: (2,)
160
- # # Series: '' [datetime[μs]]
161
- # # [
162
- # # 2001-01-01 00:00:00
163
- # # 2002-01-01 00:00:00
164
- # # ]
165
- #
166
- # @example
167
- # date.dt.year
151
+ # s = Polars::Series.new("date", [Date.new(2001, 1, 1), Date.new(2002, 1, 1)])
152
+ # s.dt.year
168
153
  # # =>
169
154
  # # shape: (2,)
170
- # # Series: '' [i32]
155
+ # # Series: 'date' [i32]
171
156
  # # [
172
157
  # # 2001
173
158
  # # 2002
@@ -207,24 +192,13 @@ module Polars
207
192
  # @return [Series]
208
193
  #
209
194
  # @example
210
- # start = DateTime.new(2001, 1, 1)
211
- # stop = DateTime.new(2001, 4, 1)
212
- # date = Polars.date_range(start, stop, "1mo")
213
- # # =>
214
- # # shape: (4,)
215
- # # Series: '' [datetime[μs]]
216
- # # [
217
- # # 2001-01-01 00:00:00
218
- # # 2001-02-01 00:00:00
219
- # # 2001-03-01 00:00:00
220
- # # 2001-04-01 00:00:00
221
- # # ]
222
- #
223
- # @example
195
+ # date = Polars.date_range(
196
+ # Date.new(2001, 1, 1), Date.new(2001, 4, 1), "1mo", eager: true
197
+ # ).alias("date")
224
198
  # date.dt.quarter
225
199
  # # =>
226
200
  # # shape: (4,)
227
- # # Series: '' [i8]
201
+ # # Series: 'date' [i8]
228
202
  # # [
229
203
  # # 1
230
204
  # # 1
@@ -245,24 +219,13 @@ module Polars
245
219
  # @return [Series]
246
220
  #
247
221
  # @example
248
- # start = DateTime.new(2001, 1, 1)
249
- # stop = DateTime.new(2001, 4, 1)
250
- # date = Polars.date_range(start, stop, "1mo")
251
- # # =>
252
- # # shape: (4,)
253
- # # Series: '' [datetime[μs]]
254
- # # [
255
- # # 2001-01-01 00:00:00
256
- # # 2001-02-01 00:00:00
257
- # # 2001-03-01 00:00:00
258
- # # 2001-04-01 00:00:00
259
- # # ]
260
- #
261
- # @example
222
+ # date = Polars.date_range(
223
+ # Date.new(2001, 1, 1), Date.new(2001, 4, 1), "1mo", eager: true
224
+ # ).alias("date")
262
225
  # date.dt.month
263
226
  # # =>
264
227
  # # shape: (4,)
265
- # # Series: '' [i8]
228
+ # # Series: 'date' [i8]
266
229
  # # [
267
230
  # # 1
268
231
  # # 2
@@ -283,24 +246,13 @@ module Polars
283
246
  # @return [Series]
284
247
  #
285
248
  # @example
286
- # start = DateTime.new(2001, 1, 1)
287
- # stop = DateTime.new(2001, 4, 1)
288
- # date = Polars.date_range(start, stop, "1mo")
289
- # # =>
290
- # # shape: (4,)
291
- # # Series: '' [datetime[μs]]
292
- # # [
293
- # # 2001-01-01 00:00:00
294
- # # 2001-02-01 00:00:00
295
- # # 2001-03-01 00:00:00
296
- # # 2001-04-01 00:00:00
297
- # # ]
298
- #
299
- # @example
249
+ # date = Polars.date_range(
250
+ # Date.new(2001, 1, 1), Date.new(2001, 4, 1), "1mo", eager: true
251
+ # ).alias("date")
300
252
  # date.dt.week
301
253
  # # =>
302
254
  # # shape: (4,)
303
- # # Series: '' [i8]
255
+ # # Series: 'date' [i8]
304
256
  # # [
305
257
  # # 1
306
258
  # # 5
@@ -320,27 +272,13 @@ module Polars
320
272
  # @return [Series]
321
273
  #
322
274
  # @example
323
- # start = DateTime.new(2001, 1, 1)
324
- # stop = DateTime.new(2001, 1, 7)
325
- # date = Polars.date_range(start, stop, "1d")
326
- # # =>
327
- # # shape: (7,)
328
- # # Series: '' [datetime[μs]]
329
- # # [
330
- # # 2001-01-01 00:00:00
331
- # # 2001-01-02 00:00:00
332
- # # 2001-01-03 00:00:00
333
- # # 2001-01-04 00:00:00
334
- # # 2001-01-05 00:00:00
335
- # # 2001-01-06 00:00:00
336
- # # 2001-01-07 00:00:00
337
- # # ]
338
- #
339
- # @example
340
- # date.dt.weekday
275
+ # s = Polars.date_range(Date.new(2001, 1, 1), Date.new(2001, 1, 7), eager: true).alias(
276
+ # "date"
277
+ # )
278
+ # s.dt.weekday
341
279
  # # =>
342
280
  # # shape: (7,)
343
- # # Series: '' [i8]
281
+ # # Series: 'date' [i8]
344
282
  # # [
345
283
  # # 1
346
284
  # # 2
@@ -364,25 +302,13 @@ module Polars
364
302
  # @return [Series]
365
303
  #
366
304
  # @example
367
- # start = DateTime.new(2001, 1, 1)
368
- # stop = DateTime.new(2001, 1, 9)
369
- # date = Polars.date_range(start, stop, "2d")
370
- # # =>
371
- # # shape: (5,)
372
- # # Series: '' [datetime[μs]]
373
- # # [
374
- # # 2001-01-01 00:00:00
375
- # # 2001-01-03 00:00:00
376
- # # 2001-01-05 00:00:00
377
- # # 2001-01-07 00:00:00
378
- # # 2001-01-09 00:00:00
379
- # # ]
380
- #
381
- # @example
382
- # date.dt.day
305
+ # s = Polars.date_range(
306
+ # Date.new(2001, 1, 1), Date.new(2001, 1, 9), "2d", eager: true
307
+ # ).alias("date")
308
+ # s.dt.day
383
309
  # # =>
384
310
  # # shape: (5,)
385
- # # Series: '' [i8]
311
+ # # Series: 'date' [i8]
386
312
  # # [
387
313
  # # 1
388
314
  # # 3
@@ -404,23 +330,13 @@ module Polars
404
330
  # @return [Series]
405
331
  #
406
332
  # @example
407
- # start = DateTime.new(2001, 1, 1)
408
- # stop = DateTime.new(2001, 3, 1)
409
- # date = Polars.date_range(start, stop, "1mo")
410
- # # =>
411
- # # shape: (3,)
412
- # # Series: '' [datetime[μs]]
413
- # # [
414
- # # 2001-01-01 00:00:00
415
- # # 2001-02-01 00:00:00
416
- # # 2001-03-01 00:00:00
417
- # # ]
418
- #
419
- # @example
420
- # date.dt.ordinal_day
333
+ # s = Polars.date_range(
334
+ # Date.new(2001, 1, 1), Date.new(2001, 3, 1), "1mo", eager: true
335
+ # ).alias("date")
336
+ # s.dt.ordinal_day
421
337
  # # =>
422
338
  # # shape: (3,)
423
- # # Series: '' [i16]
339
+ # # Series: 'date' [i16]
424
340
  # # [
425
341
  # # 1
426
342
  # # 32
@@ -441,22 +357,11 @@ module Polars
441
357
  # @example
442
358
  # start = DateTime.new(2001, 1, 1)
443
359
  # stop = DateTime.new(2001, 1, 1, 3)
444
- # date = Polars.date_range(start, stop, "1h")
445
- # # =>
446
- # # shape: (4,)
447
- # # Series: '' [datetime[μs]]
448
- # # [
449
- # # 2001-01-01 00:00:00
450
- # # 2001-01-01 01:00:00
451
- # # 2001-01-01 02:00:00
452
- # # 2001-01-01 03:00:00
453
- # # ]
454
- #
455
- # @example
360
+ # date = Polars.datetime_range(start, stop, "1h", eager: true).alias("datetime")
456
361
  # date.dt.hour
457
362
  # # =>
458
363
  # # shape: (4,)
459
- # # Series: '' [i8]
364
+ # # Series: 'datetime' [i8]
460
365
  # # [
461
366
  # # 0
462
367
  # # 1
@@ -478,21 +383,11 @@ module Polars
478
383
  # @example
479
384
  # start = DateTime.new(2001, 1, 1)
480
385
  # stop = DateTime.new(2001, 1, 1, 0, 4, 0)
481
- # date = Polars.date_range(start, stop, "2m")
482
- # # =>
483
- # # shape: (3,)
484
- # # Series: '' [datetime[μs]]
485
- # # [
486
- # # 2001-01-01 00:00:00
487
- # # 2001-01-01 00:02:00
488
- # # 2001-01-01 00:04:00
489
- # # ]
490
- #
491
- # @example
386
+ # date = Polars.datetime_range(start, stop, "2m", eager: true).alias("datetime")
492
387
  # date.dt.minute
493
388
  # # =>
494
389
  # # shape: (3,)
495
- # # Series: '' [i8]
390
+ # # Series: 'datetime' [i8]
496
391
  # # [
497
392
  # # 0
498
393
  # # 2
@@ -515,27 +410,11 @@ module Polars
515
410
  # @example
516
411
  # start = DateTime.new(2001, 1, 1)
517
412
  # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
518
- # date = Polars.date_range(start, stop, "500ms")
519
- # # =>
520
- # # shape: (9,)
521
- # # Series: '' [datetime[μs]]
522
- # # [
523
- # # 2001-01-01 00:00:00
524
- # # 2001-01-01 00:00:00.500
525
- # # 2001-01-01 00:00:01
526
- # # 2001-01-01 00:00:01.500
527
- # # 2001-01-01 00:00:02
528
- # # 2001-01-01 00:00:02.500
529
- # # 2001-01-01 00:00:03
530
- # # 2001-01-01 00:00:03.500
531
- # # 2001-01-01 00:00:04
532
- # # ]
533
- #
534
- # @example
413
+ # date = Polars.datetime_range(start, stop, "500ms", eager: true).alias("datetime")
535
414
  # date.dt.second
536
415
  # # =>
537
416
  # # shape: (9,)
538
- # # Series: '' [i8]
417
+ # # Series: 'datetime' [i8]
539
418
  # # [
540
419
  # # 0
541
420
  # # 0
@@ -552,7 +431,7 @@ module Polars
552
431
  # date.dt.second(fractional: true)
553
432
  # # =>
554
433
  # # shape: (9,)
555
- # # Series: '' [f64]
434
+ # # Series: 'datetime' [f64]
556
435
  # # [
557
436
  # # 0.0
558
437
  # # 0.5
@@ -577,27 +456,11 @@ module Polars
577
456
  # @example
578
457
  # start = DateTime.new(2001, 1, 1)
579
458
  # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
580
- # date = Polars.date_range(start, stop, "500ms")
581
- # # =>
582
- # # shape: (9,)
583
- # # Series: '' [datetime[μs]]
584
- # # [
585
- # # 2001-01-01 00:00:00
586
- # # 2001-01-01 00:00:00.500
587
- # # 2001-01-01 00:00:01
588
- # # 2001-01-01 00:00:01.500
589
- # # 2001-01-01 00:00:02
590
- # # 2001-01-01 00:00:02.500
591
- # # 2001-01-01 00:00:03
592
- # # 2001-01-01 00:00:03.500
593
- # # 2001-01-01 00:00:04
594
- # # ]
595
- #
596
- # @example
459
+ # date = Polars.datetime_range(start, stop, "500ms", eager: true).alias("datetime")
597
460
  # date.dt.millisecond
598
461
  # # =>
599
462
  # # shape: (9,)
600
- # # Series: '' [i32]
463
+ # # Series: 'datetime' [i32]
601
464
  # # [
602
465
  # # 0
603
466
  # # 500
@@ -622,27 +485,11 @@ module Polars
622
485
  # @example
623
486
  # start = DateTime.new(2001, 1, 1)
624
487
  # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
625
- # date = Polars.date_range(start, stop, "500ms")
626
- # # =>
627
- # # shape: (9,)
628
- # # Series: '' [datetime[μs]]
629
- # # [
630
- # # 2001-01-01 00:00:00
631
- # # 2001-01-01 00:00:00.500
632
- # # 2001-01-01 00:00:01
633
- # # 2001-01-01 00:00:01.500
634
- # # 2001-01-01 00:00:02
635
- # # 2001-01-01 00:00:02.500
636
- # # 2001-01-01 00:00:03
637
- # # 2001-01-01 00:00:03.500
638
- # # 2001-01-01 00:00:04
639
- # # ]
640
- #
641
- # @example
488
+ # date = Polars.datetime_range(start, stop, "500ms", eager: true).alias("datetime")
642
489
  # date.dt.microsecond
643
490
  # # =>
644
491
  # # shape: (9,)
645
- # # Series: '' [i32]
492
+ # # Series: 'datetime' [i32]
646
493
  # # [
647
494
  # # 0
648
495
  # # 500000
@@ -667,27 +514,11 @@ module Polars
667
514
  # @example
668
515
  # start = DateTime.new(2001, 1, 1)
669
516
  # stop = DateTime.new(2001, 1, 1, 0, 0, 4)
670
- # date = Polars.date_range(start, stop, "500ms")
671
- # # =>
672
- # # shape: (9,)
673
- # # Series: '' [datetime[μs]]
674
- # # [
675
- # # 2001-01-01 00:00:00
676
- # # 2001-01-01 00:00:00.500
677
- # # 2001-01-01 00:00:01
678
- # # 2001-01-01 00:00:01.500
679
- # # 2001-01-01 00:00:02
680
- # # 2001-01-01 00:00:02.500
681
- # # 2001-01-01 00:00:03
682
- # # 2001-01-01 00:00:03.500
683
- # # 2001-01-01 00:00:04
684
- # # ]
685
- #
686
- # @example
517
+ # date = Polars.datetime_range(start, stop, "500ms", eager: true).alias("datetime")
687
518
  # date.dt.nanosecond
688
519
  # # =>
689
520
  # # shape: (9,)
690
- # # Series: '' [i32]
521
+ # # Series: 'datetime' [i32]
691
522
  # # [
692
523
  # # 0
693
524
  # # 500000000
@@ -705,7 +536,7 @@ module Polars
705
536
 
706
537
  # Return a timestamp in the given time unit.
707
538
  #
708
- # @param tu ["us", "ns", "ms"]
539
+ # @param time_unit ["us", "ns", "ms"]
709
540
  # Time unit.
710
541
  #
711
542
  # @return [Series]
@@ -713,10 +544,10 @@ module Polars
713
544
  # @example
714
545
  # start = DateTime.new(2001, 1, 1)
715
546
  # stop = DateTime.new(2001, 1, 3)
716
- # date = Polars.date_range(start, stop, "1d")
547
+ # date = Polars.datetime_range(start, stop, "1d", eager: true).alias("datetime")
717
548
  # # =>
718
549
  # # shape: (3,)
719
- # # Series: '' [datetime[μs]]
550
+ # # Series: 'datetime' [datetime[ns]]
720
551
  # # [
721
552
  # # 2001-01-01 00:00:00
722
553
  # # 2001-01-02 00:00:00
@@ -744,13 +575,13 @@ module Polars
744
575
  # # 978393600000000000
745
576
  # # 978480000000000000
746
577
  # # ]
747
- def timestamp(tu = "us")
578
+ def timestamp(time_unit = "us")
748
579
  super
749
580
  end
750
581
 
751
582
  # Get the time passed since the Unix EPOCH in the give time unit.
752
583
  #
753
- # @param tu ["us", "ns", "ms", "s", "d"]
584
+ # @param time_unit ["us", "ns", "ms", "s", "d"]
754
585
  # Time unit.
755
586
  #
756
587
  # @return [Series]
@@ -758,10 +589,10 @@ module Polars
758
589
  # @example
759
590
  # start = DateTime.new(2001, 1, 1)
760
591
  # stop = DateTime.new(2001, 1, 3)
761
- # date = Polars.date_range(start, stop, "1d")
592
+ # date = Polars.datetime_range(start, stop, "1d", eager: true).alias("datetime")
762
593
  # # =>
763
594
  # # shape: (3,)
764
- # # Series: '' [datetime[μs]]
595
+ # # Series: 'datetime' [datetime[ns]]
765
596
  # # [
766
597
  # # 2001-01-01 00:00:00
767
598
  # # 2001-01-02 00:00:00
@@ -789,7 +620,7 @@ module Polars
789
620
  # # 978393600
790
621
  # # 978480000
791
622
  # # ]
792
- def epoch(tu = "us")
623
+ def epoch(time_unit = "us")
793
624
  super
794
625
  end
795
626
 
@@ -798,7 +629,7 @@ module Polars
798
629
  # This does not modify underlying data, and should be used to fix an incorrect
799
630
  # time unit.
800
631
  #
801
- # @param tu ["ns", "us", "ms"]
632
+ # @param time_unit ["ns", "us", "ms"]
802
633
  # Time unit for the `Datetime` Series.
803
634
  #
804
635
  # @return [Series]
@@ -806,10 +637,10 @@ module Polars
806
637
  # @example
807
638
  # start = DateTime.new(2001, 1, 1)
808
639
  # stop = DateTime.new(2001, 1, 3)
809
- # date = Polars.date_range(start, stop, "1d", time_unit: "ns")
640
+ # date = Polars.datetime_range(start, stop, "1d", time_unit: "ns", eager: true).alias("datetime")
810
641
  # # =>
811
642
  # # shape: (3,)
812
- # # Series: '' [datetime[ns]]
643
+ # # Series: 'datetime' [datetime[ns]]
813
644
  # # [
814
645
  # # 2001-01-01 00:00:00
815
646
  # # 2001-01-02 00:00:00
@@ -826,13 +657,13 @@ module Polars
826
657
  # # +32974-01-22 00:00:00
827
658
  # # +32976-10-18 00:00:00
828
659
  # # ]
829
- def with_time_unit(tu)
660
+ def with_time_unit(time_unit)
830
661
  super
831
662
  end
832
663
 
833
664
  # Cast the underlying data to another time unit. This may lose precision.
834
665
  #
835
- # @param tu ["ns", "us", "ms"]
666
+ # @param time_unit ["ns", "us", "ms"]
836
667
  # Time unit for the `Datetime` Series.
837
668
  #
838
669
  # @return [Series]
@@ -840,10 +671,10 @@ module Polars
840
671
  # @example
841
672
  # start = DateTime.new(2001, 1, 1)
842
673
  # stop = DateTime.new(2001, 1, 3)
843
- # date = Polars.date_range(start, stop, "1d")
674
+ # date = Polars.datetime_range(start, stop, "1d", eager: true).alias("datetime")
844
675
  # # =>
845
676
  # # shape: (3,)
846
- # # Series: '' [datetime[μs]]
677
+ # # Series: 'datetime' [datetime[ns]]
847
678
  # # [
848
679
  # # 2001-01-01 00:00:00
849
680
  # # 2001-01-02 00:00:00
@@ -871,13 +702,13 @@ module Polars
871
702
  # # 2001-01-02 00:00:00
872
703
  # # 2001-01-03 00:00:00
873
704
  # # ]
874
- def cast_time_unit(tu)
705
+ def cast_time_unit(time_unit)
875
706
  super
876
707
  end
877
708
 
878
709
  # Set time zone a Series of type Datetime.
879
710
  #
880
- # @param tz [String]
711
+ # @param time_zone [String]
881
712
  # Time zone for the `Datetime` Series.
882
713
  #
883
714
  # @return [Series]
@@ -885,10 +716,10 @@ module Polars
885
716
  # @example
886
717
  # start = DateTime.new(2020, 3, 1)
887
718
  # stop = DateTime.new(2020, 5, 1)
888
- # date = Polars.date_range(start, stop, "1mo", time_zone: "UTC")
719
+ # date = Polars.datetime_range(start, stop, "1mo", time_zone: "UTC", eager: true).alias("datetime")
889
720
  # # =>
890
721
  # # shape: (3,)
891
- # # Series: '' [datetime[μs, UTC]]
722
+ # # Series: 'datetime' [datetime[ns, UTC]]
892
723
  # # [
893
724
  # # 2020-03-01 00:00:00 UTC
894
725
  # # 2020-04-01 00:00:00 UTC
@@ -899,13 +730,13 @@ module Polars
899
730
  # date.dt.convert_time_zone("Europe/London").alias("London")
900
731
  # # =>
901
732
  # # shape: (3,)
902
- # # Series: 'London' [datetime[μs, Europe/London]]
733
+ # # Series: 'London' [datetime[ns, Europe/London]]
903
734
  # # [
904
735
  # # 2020-03-01 00:00:00 GMT
905
736
  # # 2020-04-01 01:00:00 BST
906
737
  # # 2020-05-01 01:00:00 BST
907
738
  # # ]
908
- def convert_time_zone(tz)
739
+ def convert_time_zone(time_zone)
909
740
  super
910
741
  end
911
742
 
@@ -916,8 +747,6 @@ module Polars
916
747
  #
917
748
  # @param time_zone [String]
918
749
  # Time zone for the `Datetime` Series. Pass `nil` to unset time zone.
919
- # @param use_earliest [Boolean]
920
- # Determine how to deal with ambiguous datetimes.
921
750
  # @param ambiguous [String]
922
751
  # Determine how to deal with ambiguous datetimes.
923
752
  # @param non_existent [String]
@@ -928,10 +757,10 @@ module Polars
928
757
  # @example
929
758
  # start = DateTime.new(2020, 3, 1)
930
759
  # stop = DateTime.new(2020, 5, 1)
931
- # date = Polars.date_range(start, stop, "1mo", time_zone: "UTC")
760
+ # date = Polars.datetime_range(start, stop, "1mo", time_zone: "UTC", eager: true).alias("datetime")
932
761
  # # =>
933
762
  # # shape: (3,)
934
- # # Series: '' [datetime[μs, UTC]]
763
+ # # Series: 'datetime' [datetime[ns, UTC]]
935
764
  # # [
936
765
  # # 2020-03-01 00:00:00 UTC
937
766
  # # 2020-04-01 00:00:00 UTC
@@ -942,7 +771,7 @@ module Polars
942
771
  # date.dt.epoch("s")
943
772
  # # =>
944
773
  # # shape: (3,)
945
- # # Series: '' [i64]
774
+ # # Series: 'datetime' [i64]
946
775
  # # [
947
776
  # # 1583020800
948
777
  # # 1585699200
@@ -953,7 +782,7 @@ module Polars
953
782
  # date = date.dt.convert_time_zone("Europe/London").alias("London")
954
783
  # # =>
955
784
  # # shape: (3,)
956
- # # Series: 'London' [datetime[μs, Europe/London]]
785
+ # # Series: 'London' [datetime[ns, Europe/London]]
957
786
  # # [
958
787
  # # 2020-03-01 00:00:00 GMT
959
788
  # # 2020-04-01 01:00:00 BST
@@ -975,7 +804,7 @@ module Polars
975
804
  # date = date.dt.replace_time_zone("America/New_York").alias("NYC")
976
805
  # # =>
977
806
  # # shape: (3,)
978
- # # Series: 'NYC' [datetime[μs, America/New_York]]
807
+ # # Series: 'NYC' [datetime[ns, America/New_York]]
979
808
  # # [
980
809
  # # 2020-03-01 00:00:00 EST
981
810
  # # 2020-04-01 01:00:00 EDT
@@ -992,7 +821,7 @@ module Polars
992
821
  # # 1585717200
993
822
  # # 1588309200
994
823
  # # ]
995
- def replace_time_zone(time_zone, use_earliest: nil, ambiguous: "raise", non_existent: "raise")
824
+ def replace_time_zone(time_zone, ambiguous: "raise", non_existent: "raise")
996
825
  super
997
826
  end
998
827
 
@@ -1014,39 +843,32 @@ module Polars
1014
843
  # @return [Series]
1015
844
  #
1016
845
  # @example
1017
- # date = Polars.date_range(DateTime.new(2020, 3, 1), DateTime.new(2020, 5, 1), "1mo")
1018
- # # =>
1019
- # # shape: (3,)
1020
- # # Series: '' [datetime[μs]]
1021
- # # [
1022
- # # 2020-03-01 00:00:00
1023
- # # 2020-04-01 00:00:00
1024
- # # 2020-05-01 00:00:00
1025
- # # ]
1026
- #
1027
- # @example
1028
- # date.diff.dt.days
846
+ # date = Polars.datetime_range(
847
+ # Time.utc(2020, 3, 1), Time.utc(2020, 5, 1), "1mo", eager: true
848
+ # ).alias("datetime")
849
+ # date.diff.dt.total_days
1029
850
  # # =>
1030
851
  # # shape: (3,)
1031
- # # Series: '' [i64]
852
+ # # Series: 'datetime' [i64]
1032
853
  # # [
1033
854
  # # null
1034
855
  # # 31
1035
856
  # # 30
1036
857
  # # ]
1037
- def days
858
+ def total_days
1038
859
  super
1039
860
  end
861
+ alias_method :days, :total_days
1040
862
 
1041
863
  # Extract the hours from a Duration type.
1042
864
  #
1043
865
  # @return [Series]
1044
866
  #
1045
867
  # @example
1046
- # date = Polars.date_range(DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 4), "1d")
868
+ # date = Polars.datetime_range(DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 4), "1d", time_unit: "us", eager: true).alias("datetime")
1047
869
  # # =>
1048
870
  # # shape: (4,)
1049
- # # Series: '' [datetime[μs]]
871
+ # # Series: 'datetime' [datetime[μs]]
1050
872
  # # [
1051
873
  # # 2020-01-01 00:00:00
1052
874
  # # 2020-01-02 00:00:00
@@ -1055,29 +877,30 @@ module Polars
1055
877
  # # ]
1056
878
  #
1057
879
  # @example
1058
- # date.diff.dt.hours
880
+ # date.diff.dt.total_hours
1059
881
  # # =>
1060
882
  # # shape: (4,)
1061
- # # Series: '' [i64]
883
+ # # Series: 'datetime' [i64]
1062
884
  # # [
1063
885
  # # null
1064
886
  # # 24
1065
887
  # # 24
1066
888
  # # 24
1067
889
  # # ]
1068
- def hours
890
+ def total_hours
1069
891
  super
1070
892
  end
893
+ alias_method :hours, :total_hours
1071
894
 
1072
895
  # Extract the minutes from a Duration type.
1073
896
  #
1074
897
  # @return [Series]
1075
898
  #
1076
899
  # @example
1077
- # date = Polars.date_range(DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 4), "1d")
900
+ # date = Polars.datetime_range(DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 4), "1d", time_unit: "us", eager: true).alias("datetime")
1078
901
  # # =>
1079
902
  # # shape: (4,)
1080
- # # Series: '' [datetime[μs]]
903
+ # # Series: 'datetime' [datetime[μs]]
1081
904
  # # [
1082
905
  # # 2020-01-01 00:00:00
1083
906
  # # 2020-01-02 00:00:00
@@ -1086,31 +909,32 @@ module Polars
1086
909
  # # ]
1087
910
  #
1088
911
  # @example
1089
- # date.diff.dt.minutes
912
+ # date.diff.dt.total_minutes
1090
913
  # # =>
1091
914
  # # shape: (4,)
1092
- # # Series: '' [i64]
915
+ # # Series: 'datetime' [i64]
1093
916
  # # [
1094
917
  # # null
1095
918
  # # 1440
1096
919
  # # 1440
1097
920
  # # 1440
1098
921
  # # ]
1099
- def minutes
922
+ def total_minutes
1100
923
  super
1101
924
  end
925
+ alias_method :minutes, :total_minutes
1102
926
 
1103
927
  # Extract the seconds from a Duration type.
1104
928
  #
1105
929
  # @return [Series]
1106
930
  #
1107
931
  # @example
1108
- # date = Polars.date_range(
1109
- # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 4, 0), "1m"
1110
- # )
932
+ # date = Polars.datetime_range(
933
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 4, 0), "1m", time_unit: "us", eager: true
934
+ # ).alias("datetime")
1111
935
  # # =>
1112
936
  # # shape: (5,)
1113
- # # Series: '' [datetime[μs]]
937
+ # # Series: 'datetime' [datetime[μs]]
1114
938
  # # [
1115
939
  # # 2020-01-01 00:00:00
1116
940
  # # 2020-01-01 00:01:00
@@ -1120,10 +944,10 @@ module Polars
1120
944
  # # ]
1121
945
  #
1122
946
  # @example
1123
- # date.diff.dt.seconds
947
+ # date.diff.dt.total_seconds
1124
948
  # # =>
1125
949
  # # shape: (5,)
1126
- # # Series: '' [i64]
950
+ # # Series: 'datetime' [i64]
1127
951
  # # [
1128
952
  # # null
1129
953
  # # 60
@@ -1131,21 +955,22 @@ module Polars
1131
955
  # # 60
1132
956
  # # 60
1133
957
  # # ]
1134
- def seconds
958
+ def total_seconds
1135
959
  super
1136
960
  end
961
+ alias_method :seconds, :total_seconds
1137
962
 
1138
963
  # Extract the milliseconds from a Duration type.
1139
964
  #
1140
965
  # @return [Series]
1141
966
  #
1142
967
  # @example
1143
- # date = Polars.date_range(
1144
- # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms"
1145
- # )[0..2]
968
+ # date = Polars.datetime_range(
969
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms", time_unit: "us", eager: true
970
+ # ).alias("datetime")[0..2]
1146
971
  # # =>
1147
972
  # # shape: (3,)
1148
- # # Series: '' [datetime[μs]]
973
+ # # Series: 'datetime' [datetime[μs]]
1149
974
  # # [
1150
975
  # # 2020-01-01 00:00:00
1151
976
  # # 2020-01-01 00:00:00.001
@@ -1153,30 +978,31 @@ module Polars
1153
978
  # # ]
1154
979
  #
1155
980
  # @example
1156
- # date.diff.dt.milliseconds
981
+ # date.diff.dt.total_milliseconds
1157
982
  # # =>
1158
983
  # # shape: (3,)
1159
- # # Series: '' [i64]
984
+ # # Series: 'datetime' [i64]
1160
985
  # # [
1161
986
  # # null
1162
987
  # # 1
1163
988
  # # 1
1164
989
  # # ]
1165
- def milliseconds
990
+ def total_milliseconds
1166
991
  super
1167
992
  end
993
+ alias_method :milliseconds, :total_milliseconds
1168
994
 
1169
995
  # Extract the microseconds from a Duration type.
1170
996
  #
1171
997
  # @return [Series]
1172
998
  #
1173
999
  # @example
1174
- # date = Polars.date_range(
1175
- # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms"
1176
- # )[0..2]
1000
+ # date = Polars.datetime_range(
1001
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms", time_unit: "us", eager: true
1002
+ # ).alias("datetime")[0..2]
1177
1003
  # # =>
1178
1004
  # # shape: (3,)
1179
- # # Series: '' [datetime[μs]]
1005
+ # # Series: 'datetime' [datetime[μs]]
1180
1006
  # # [
1181
1007
  # # 2020-01-01 00:00:00
1182
1008
  # # 2020-01-01 00:00:00.001
@@ -1184,30 +1010,31 @@ module Polars
1184
1010
  # # ]
1185
1011
  #
1186
1012
  # @example
1187
- # date.diff.dt.microseconds
1013
+ # date.diff.dt.total_microseconds
1188
1014
  # # =>
1189
1015
  # # shape: (3,)
1190
- # # Series: '' [i64]
1016
+ # # Series: 'datetime' [i64]
1191
1017
  # # [
1192
1018
  # # null
1193
1019
  # # 1000
1194
1020
  # # 1000
1195
1021
  # # ]
1196
- def microseconds
1022
+ def total_microseconds
1197
1023
  super
1198
1024
  end
1025
+ alias_method :microseconds, :total_microseconds
1199
1026
 
1200
1027
  # Extract the nanoseconds from a Duration type.
1201
1028
  #
1202
1029
  # @return [Series]
1203
1030
  #
1204
1031
  # @example
1205
- # date = Polars.date_range(
1206
- # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms"
1207
- # )[0..2]
1032
+ # date = Polars.datetime_range(
1033
+ # DateTime.new(2020, 1, 1), DateTime.new(2020, 1, 1, 0, 0, 1, 0), "1ms", time_unit: "us", eager: true
1034
+ # ).alias("datetime")[0..2]
1208
1035
  # # =>
1209
1036
  # # shape: (3,)
1210
- # # Series: '' [datetime[μs]]
1037
+ # # Series: 'datetime' [datetime[μs]]
1211
1038
  # # [
1212
1039
  # # 2020-01-01 00:00:00
1213
1040
  # # 2020-01-01 00:00:00.001
@@ -1215,18 +1042,19 @@ module Polars
1215
1042
  # # ]
1216
1043
  #
1217
1044
  # @example
1218
- # date.diff.dt.nanoseconds
1045
+ # date.diff.dt.total_nanoseconds
1219
1046
  # # =>
1220
1047
  # # shape: (3,)
1221
- # # Series: '' [i64]
1048
+ # # Series: 'datetime' [i64]
1222
1049
  # # [
1223
1050
  # # null
1224
1051
  # # 1000000
1225
1052
  # # 1000000
1226
1053
  # # ]
1227
- def nanoseconds
1054
+ def total_nanoseconds
1228
1055
  super
1229
1056
  end
1057
+ alias_method :nanoseconds, :total_nanoseconds
1230
1058
 
1231
1059
  # Offset this date by a relative time offset.
1232
1060
  #
@@ -1252,10 +1080,12 @@ module Polars
1252
1080
  # @return [Series]
1253
1081
  #
1254
1082
  # @example
1255
- # dates = Polars.date_range(DateTime.new(2000, 1, 1), DateTime.new(2005, 1, 1), "1y")
1083
+ # dates = Polars.datetime_range(
1084
+ # DateTime.new(2000, 1, 1), DateTime.new(2005, 1, 1), "1y", eager: true
1085
+ # ).alias("datetime")
1256
1086
  # # =>
1257
1087
  # # shape: (6,)
1258
- # # Series: '' [datetime[μs]]
1088
+ # # Series: 'datetime' [datetime[ns]]
1259
1089
  # # [
1260
1090
  # # 2000-01-01 00:00:00
1261
1091
  # # 2001-01-01 00:00:00
@@ -1269,7 +1099,7 @@ module Polars
1269
1099
  # dates.dt.offset_by("1y").alias("date_plus_1y")
1270
1100
  # # =>
1271
1101
  # # shape: (6,)
1272
- # # Series: 'date_plus_1y' [datetime[μs]]
1102
+ # # Series: 'date_plus_1y' [datetime[ns]]
1273
1103
  # # [
1274
1104
  # # 2001-01-01 00:00:00
1275
1105
  # # 2002-01-01 00:00:00
@@ -1283,7 +1113,7 @@ module Polars
1283
1113
  # dates.dt.offset_by("-1y2mo").alias("date_minus_1y_2mon")
1284
1114
  # # =>
1285
1115
  # # shape: (6,)
1286
- # # Series: 'date_minus_1y_2mon' [datetime[μs]]
1116
+ # # Series: 'date_minus_1y_2mon' [datetime[ns]]
1287
1117
  # # [
1288
1118
  # # 1998-11-01 00:00:00
1289
1119
  # # 1999-11-01 00:00:00
@@ -1318,79 +1148,9 @@ module Polars
1318
1148
  #
1319
1149
  # @param every [String]
1320
1150
  # Every interval start and period length.
1321
- # @param offset [String]
1322
- # Offset the window.
1323
1151
  #
1324
1152
  # @return [Series]
1325
- #
1326
- # @example
1327
- # start = DateTime.new(2001, 1, 1)
1328
- # stop = DateTime.new(2001, 1, 2)
1329
- # s = Polars.date_range(start, stop, "165m", name: "dates")
1330
- # # =>
1331
- # # shape: (9,)
1332
- # # Series: 'dates' [datetime[μs]]
1333
- # # [
1334
- # # 2001-01-01 00:00:00
1335
- # # 2001-01-01 02:45:00
1336
- # # 2001-01-01 05:30:00
1337
- # # 2001-01-01 08:15:00
1338
- # # 2001-01-01 11:00:00
1339
- # # 2001-01-01 13:45:00
1340
- # # 2001-01-01 16:30:00
1341
- # # 2001-01-01 19:15:00
1342
- # # 2001-01-01 22:00:00
1343
- # # ]
1344
- #
1345
- # @example
1346
- # s.dt.truncate("1h")
1347
- # # =>
1348
- # # shape: (9,)
1349
- # # Series: 'dates' [datetime[μs]]
1350
- # # [
1351
- # # 2001-01-01 00:00:00
1352
- # # 2001-01-01 02:00:00
1353
- # # 2001-01-01 05:00:00
1354
- # # 2001-01-01 08:00:00
1355
- # # 2001-01-01 11:00:00
1356
- # # 2001-01-01 13:00:00
1357
- # # 2001-01-01 16:00:00
1358
- # # 2001-01-01 19:00:00
1359
- # # 2001-01-01 22:00:00
1360
- # # ]
1361
- #
1362
- # @example
1363
- # start = DateTime.new(2001, 1, 1)
1364
- # stop = DateTime.new(2001, 1, 1, 1)
1365
- # s = Polars.date_range(start, stop, "10m", name: "dates")
1366
- # # =>
1367
- # # shape: (7,)
1368
- # # Series: 'dates' [datetime[μs]]
1369
- # # [
1370
- # # 2001-01-01 00:00:00
1371
- # # 2001-01-01 00:10:00
1372
- # # 2001-01-01 00:20:00
1373
- # # 2001-01-01 00:30:00
1374
- # # 2001-01-01 00:40:00
1375
- # # 2001-01-01 00:50:00
1376
- # # 2001-01-01 01:00:00
1377
- # # ]
1378
- #
1379
- # @example
1380
- # s.dt.truncate("30m")
1381
- # # =>
1382
- # # shape: (7,)
1383
- # # Series: 'dates' [datetime[μs]]
1384
- # # [
1385
- # # 2001-01-01 00:00:00
1386
- # # 2001-01-01 00:00:00
1387
- # # 2001-01-01 00:00:00
1388
- # # 2001-01-01 00:30:00
1389
- # # 2001-01-01 00:30:00
1390
- # # 2001-01-01 00:30:00
1391
- # # 2001-01-01 01:00:00
1392
- # # ]
1393
- def truncate(every, offset: nil, use_earliest: nil)
1153
+ def truncate(every)
1394
1154
  super
1395
1155
  end
1396
1156
 
@@ -1419,69 +1179,108 @@ module Polars
1419
1179
  #
1420
1180
  # @param every [String]
1421
1181
  # Every interval start and period length.
1422
- # @param offset [String]
1423
- # Offset the window.
1424
1182
  #
1425
1183
  # @return [Series]
1426
1184
  #
1427
1185
  # @note
1428
1186
  # This functionality is currently experimental and may
1429
1187
  # change without it being considered a breaking change.
1188
+ def round(every)
1189
+ super
1190
+ end
1191
+
1192
+ # Roll backward to the first day of the month.
1193
+ #
1194
+ # @return [Series]
1430
1195
  #
1431
1196
  # @example
1432
- # start = DateTime.new(2001, 1, 1)
1433
- # stop = DateTime.new(2001, 1, 2)
1434
- # s = Polars.date_range(start, stop, "165m", name: "dates")
1197
+ # s = Polars.datetime_range(
1198
+ # DateTime.new(2000, 1, 2, 2), DateTime.new(2000, 4, 2, 2), "1mo", time_unit: "us", eager: true
1199
+ # ).alias("datetime")
1200
+ # s.dt.month_start
1435
1201
  # # =>
1436
- # # shape: (9,)
1437
- # # Series: 'dates' [datetime[μs]]
1202
+ # # shape: (4,)
1203
+ # # Series: 'datetime' [datetime[μs]]
1438
1204
  # # [
1439
- # # 2001-01-01 00:00:00
1440
- # # 2001-01-01 02:45:00
1441
- # # 2001-01-01 05:30:00
1442
- # # 2001-01-01 08:15:00
1443
- # # 2001-01-01 11:00:00
1444
- # # 2001-01-01 13:45:00
1445
- # # 2001-01-01 16:30:00
1446
- # # 2001-01-01 19:15:00
1447
- # # 2001-01-01 22:00:00
1205
+ # # 2000-01-01 02:00:00
1206
+ # # 2000-02-01 02:00:00
1207
+ # # 2000-03-01 02:00:00
1208
+ # # 2000-04-01 02:00:00
1209
+ # # ]
1210
+ def month_start
1211
+ super
1212
+ end
1213
+
1214
+ # Roll forward to the last day of the month.
1215
+ #
1216
+ # @return [Series]
1217
+ #
1218
+ # @example
1219
+ # s = Polars.datetime_range(
1220
+ # DateTime.new(2000, 1, 2, 2), DateTime.new(2000, 4, 2, 2), "1mo", time_unit: "us", eager: true
1221
+ # ).alias("datetime")
1222
+ # s.dt.month_end
1223
+ # # =>
1224
+ # # shape: (4,)
1225
+ # # Series: 'datetime' [datetime[μs]]
1226
+ # # [
1227
+ # # 2000-01-31 02:00:00
1228
+ # # 2000-02-29 02:00:00
1229
+ # # 2000-03-31 02:00:00
1230
+ # # 2000-04-30 02:00:00
1448
1231
  # # ]
1232
+ def month_end
1233
+ super
1234
+ end
1235
+
1236
+ # Base offset from UTC.
1237
+ #
1238
+ # This is usually constant for all datetimes in a given time zone, but
1239
+ # may vary in the rare case that a country switches time zone, like
1240
+ # Samoa (Apia) did at the end of 2011.
1241
+ #
1242
+ # @return [Series]
1449
1243
  #
1450
1244
  # @example
1451
- # s.dt.round("1h")
1245
+ # s = Polars.datetime_range(
1246
+ # DateTime.new(2011, 12, 29),
1247
+ # DateTime.new(2012, 1, 1),
1248
+ # "2d",
1249
+ # time_zone: "Pacific/Apia",
1250
+ # eager: true,
1251
+ # ).alias("datetime")
1252
+ # s.dt.base_utc_offset
1452
1253
  # # =>
1453
- # # shape: (9,)
1454
- # # Series: 'dates' [datetime[μs]]
1254
+ # # shape: (2,)
1255
+ # # Series: 'datetime' [duration[ms]]
1455
1256
  # # [
1456
- # # 2001-01-01 00:00:00
1457
- # # 2001-01-01 03:00:00
1458
- # # 2001-01-01 06:00:00
1459
- # # 2001-01-01 08:00:00
1460
- # # 2001-01-01 11:00:00
1461
- # # 2001-01-01 14:00:00
1462
- # # 2001-01-01 17:00:00
1463
- # # 2001-01-01 19:00:00
1464
- # # 2001-01-01 22:00:00
1257
+ # # -11h
1258
+ # # 13h
1465
1259
  # # ]
1260
+ def base_utc_offset
1261
+ super
1262
+ end
1263
+
1264
+ # Additional offset currently in effect (typically due to daylight saving time).
1265
+ #
1266
+ # @return [Series]
1466
1267
  #
1467
1268
  # @example
1468
- # start = DateTime.new(2001, 1, 1)
1469
- # stop = DateTime.new(2001, 1, 1, 1)
1470
- # s = Polars.date_range(start, stop, "10m", name: "dates")
1471
- # s.dt.round("30m")
1269
+ # s = Polars.datetime_range(
1270
+ # DateTime.new(2020, 10, 25),
1271
+ # DateTime.new(2020, 10, 26),
1272
+ # time_zone: "Europe/London",
1273
+ # eager: true,
1274
+ # ).alias("datetime")
1275
+ # s.dt.dst_offset
1472
1276
  # # =>
1473
- # # shape: (7,)
1474
- # # Series: 'dates' [datetime[μs]]
1277
+ # # shape: (2,)
1278
+ # # Series: 'datetime' [duration[ms]]
1475
1279
  # # [
1476
- # # 2001-01-01 00:00:00
1477
- # # 2001-01-01 00:00:00
1478
- # # 2001-01-01 00:30:00
1479
- # # 2001-01-01 00:30:00
1480
- # # 2001-01-01 00:30:00
1481
- # # 2001-01-01 01:00:00
1482
- # # 2001-01-01 01:00:00
1280
+ # # 1h
1281
+ # # 0ms
1483
1282
  # # ]
1484
- def round(every, offset: nil)
1283
+ def dst_offset
1485
1284
  super
1486
1285
  end
1487
1286
  end