polars-df 0.2.0-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +33 -0
- data/Cargo.lock +2230 -0
- data/Cargo.toml +10 -0
- data/LICENSE-THIRD-PARTY.txt +38828 -0
- data/LICENSE.txt +20 -0
- data/README.md +91 -0
- data/lib/polars/3.0/polars.so +0 -0
- data/lib/polars/3.1/polars.so +0 -0
- data/lib/polars/3.2/polars.so +0 -0
- data/lib/polars/batched_csv_reader.rb +96 -0
- data/lib/polars/cat_expr.rb +52 -0
- data/lib/polars/cat_name_space.rb +54 -0
- data/lib/polars/convert.rb +100 -0
- data/lib/polars/data_frame.rb +4833 -0
- data/lib/polars/data_types.rb +122 -0
- data/lib/polars/date_time_expr.rb +1418 -0
- data/lib/polars/date_time_name_space.rb +1484 -0
- data/lib/polars/dynamic_group_by.rb +52 -0
- data/lib/polars/exceptions.rb +20 -0
- data/lib/polars/expr.rb +5307 -0
- data/lib/polars/expr_dispatch.rb +22 -0
- data/lib/polars/functions.rb +453 -0
- data/lib/polars/group_by.rb +558 -0
- data/lib/polars/io.rb +814 -0
- data/lib/polars/lazy_frame.rb +2442 -0
- data/lib/polars/lazy_functions.rb +1195 -0
- data/lib/polars/lazy_group_by.rb +93 -0
- data/lib/polars/list_expr.rb +610 -0
- data/lib/polars/list_name_space.rb +346 -0
- data/lib/polars/meta_expr.rb +54 -0
- data/lib/polars/rolling_group_by.rb +35 -0
- data/lib/polars/series.rb +3730 -0
- data/lib/polars/slice.rb +104 -0
- data/lib/polars/string_expr.rb +972 -0
- data/lib/polars/string_name_space.rb +690 -0
- data/lib/polars/struct_expr.rb +100 -0
- data/lib/polars/struct_name_space.rb +64 -0
- data/lib/polars/utils.rb +192 -0
- data/lib/polars/version.rb +4 -0
- data/lib/polars/when.rb +16 -0
- data/lib/polars/when_then.rb +19 -0
- data/lib/polars-df.rb +1 -0
- data/lib/polars.rb +50 -0
- metadata +89 -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
|
+
# date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
|
27
|
+
# # =>
|
28
|
+
# # shape: (3,)
|
29
|
+
# # Series: '' [datetime[μs]]
|
30
|
+
# # [
|
31
|
+
# # 2001-01-01 00:00:00
|
32
|
+
# # 2001-01-02 00:00:00
|
33
|
+
# # 2001-01-03 00:00:00
|
34
|
+
# # ]
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# date.dt.min
|
38
|
+
# # => 2001-01-01 00:00:00 UTC
|
39
|
+
def min
|
40
|
+
Utils.wrap_s(_s).min
|
41
|
+
end
|
42
|
+
|
43
|
+
# Return maximum as Ruby object.
|
44
|
+
#
|
45
|
+
# @return [Object]
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
|
49
|
+
# # =>
|
50
|
+
# # shape: (3,)
|
51
|
+
# # Series: '' [datetime[μs]]
|
52
|
+
# # [
|
53
|
+
# # 2001-01-01 00:00:00
|
54
|
+
# # 2001-01-02 00:00:00
|
55
|
+
# # 2001-01-03 00:00:00
|
56
|
+
# # ]
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# date.dt.max
|
60
|
+
# # => 2001-01-03 00:00:00 UTC
|
61
|
+
def max
|
62
|
+
Utils.wrap_s(_s).max
|
63
|
+
end
|
64
|
+
|
65
|
+
# Return median as Ruby object.
|
66
|
+
#
|
67
|
+
# @return [Object]
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
|
71
|
+
# # =>
|
72
|
+
# # shape: (3,)
|
73
|
+
# # Series: '' [datetime[μs]]
|
74
|
+
# # [
|
75
|
+
# # 2001-01-01 00:00:00
|
76
|
+
# # 2001-01-02 00:00:00
|
77
|
+
# # 2001-01-03 00:00:00
|
78
|
+
# # ]
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# date.dt.median
|
82
|
+
# # => 2001-01-02 00:00:00 UTC
|
83
|
+
def median
|
84
|
+
s = Utils.wrap_s(_s)
|
85
|
+
out = s.median.to_i
|
86
|
+
Utils._to_ruby_datetime(out, s.dtype, tu: s.time_unit)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Return mean as Ruby object.
|
90
|
+
#
|
91
|
+
# @return [Object]
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# date = Polars.date_range(DateTime.new(2001, 1, 1), DateTime.new(2001, 1, 3), "1d")
|
95
|
+
# # =>
|
96
|
+
# # shape: (3,)
|
97
|
+
# # Series: '' [datetime[μs]]
|
98
|
+
# # [
|
99
|
+
# # 2001-01-01 00:00:00
|
100
|
+
# # 2001-01-02 00:00:00
|
101
|
+
# # 2001-01-03 00:00:00
|
102
|
+
# # ]
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# date.dt.mean
|
106
|
+
# # => 2001-01-02 00:00:00 UTC
|
107
|
+
def mean
|
108
|
+
s = Utils.wrap_s(_s)
|
109
|
+
out = s.mean.to_i
|
110
|
+
Utils._to_ruby_datetime(out, s.dtype, tu: s.time_unit)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Format Date/datetime with a formatting rule.
|
114
|
+
#
|
115
|
+
# See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
|
116
|
+
#
|
117
|
+
# @return [Series]
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# start = DateTime.new(2001, 1, 1)
|
121
|
+
# stop = DateTime.new(2001, 1, 4)
|
122
|
+
# date = Polars.date_range(start, stop, "1d")
|
123
|
+
# # =>
|
124
|
+
# # shape: (4,)
|
125
|
+
# # Series: '' [datetime[μs]]
|
126
|
+
# # [
|
127
|
+
# # 2001-01-01 00:00:00
|
128
|
+
# # 2001-01-02 00:00:00
|
129
|
+
# # 2001-01-03 00:00:00
|
130
|
+
# # 2001-01-04 00:00:00
|
131
|
+
# # ]
|
132
|
+
#
|
133
|
+
# @example
|
134
|
+
# date.dt.strftime("%Y-%m-%d")
|
135
|
+
# # =>
|
136
|
+
# # shape: (4,)
|
137
|
+
# # Series: '' [str]
|
138
|
+
# # [
|
139
|
+
# # "2001-01-01"
|
140
|
+
# # "2001-01-02"
|
141
|
+
# # "2001-01-03"
|
142
|
+
# # "2001-01-04"
|
143
|
+
# # ]
|
144
|
+
def strftime(fmt)
|
145
|
+
super
|
146
|
+
end
|
147
|
+
|
148
|
+
# Extract the year from the underlying date representation.
|
149
|
+
#
|
150
|
+
# Applies to Date and Datetime columns.
|
151
|
+
#
|
152
|
+
# Returns the year number in the calendar date.
|
153
|
+
#
|
154
|
+
# @return [Series]
|
155
|
+
#
|
156
|
+
# @example
|
157
|
+
# start = DateTime.new(2001, 1, 1)
|
158
|
+
# stop = DateTime.new(2002, 1, 1)
|
159
|
+
# date = Polars.date_range(start, stop, "1y")
|
160
|
+
# # =>
|
161
|
+
# # shape: (2,)
|
162
|
+
# # Series: '' [datetime[μs]]
|
163
|
+
# # [
|
164
|
+
# # 2001-01-01 00:00:00
|
165
|
+
# # 2002-01-01 00:00:00
|
166
|
+
# # ]
|
167
|
+
#
|
168
|
+
# @example
|
169
|
+
# date.dt.year
|
170
|
+
# # =>
|
171
|
+
# # shape: (2,)
|
172
|
+
# # Series: '' [i32]
|
173
|
+
# # [
|
174
|
+
# # 2001
|
175
|
+
# # 2002
|
176
|
+
# # ]
|
177
|
+
def year
|
178
|
+
super
|
179
|
+
end
|
180
|
+
|
181
|
+
# Extract ISO year from underlying Date representation.
|
182
|
+
#
|
183
|
+
# Applies to Date and Datetime columns.
|
184
|
+
#
|
185
|
+
# Returns the year number according to the ISO standard.
|
186
|
+
# This may not correspond with the calendar year.
|
187
|
+
#
|
188
|
+
# @return [Series]
|
189
|
+
#
|
190
|
+
# @example
|
191
|
+
# dt = DateTime.new(2022, 1, 1, 7, 8, 40)
|
192
|
+
# Polars::Series.new([dt]).dt.iso_year
|
193
|
+
# # =>
|
194
|
+
# # shape: (1,)
|
195
|
+
# # Series: '' [i32]
|
196
|
+
# # [
|
197
|
+
# # 2021
|
198
|
+
# # ]
|
199
|
+
def iso_year
|
200
|
+
super
|
201
|
+
end
|
202
|
+
|
203
|
+
# Extract quarter from underlying Date representation.
|
204
|
+
#
|
205
|
+
# Applies to Date and Datetime columns.
|
206
|
+
#
|
207
|
+
# Returns the quarter ranging from 1 to 4.
|
208
|
+
#
|
209
|
+
# @return [Series]
|
210
|
+
#
|
211
|
+
# @example
|
212
|
+
# start = DateTime.new(2001, 1, 1)
|
213
|
+
# stop = DateTime.new(2001, 4, 1)
|
214
|
+
# date = Polars.date_range(start, stop, "1mo")
|
215
|
+
# # =>
|
216
|
+
# # shape: (4,)
|
217
|
+
# # Series: '' [datetime[μs]]
|
218
|
+
# # [
|
219
|
+
# # 2001-01-01 00:00:00
|
220
|
+
# # 2001-02-01 00:00:00
|
221
|
+
# # 2001-03-01 00:00:00
|
222
|
+
# # 2001-04-01 00:00:00
|
223
|
+
# # ]
|
224
|
+
#
|
225
|
+
# @example
|
226
|
+
# date.dt.quarter
|
227
|
+
# # =>
|
228
|
+
# # shape: (4,)
|
229
|
+
# # Series: '' [u32]
|
230
|
+
# # [
|
231
|
+
# # 1
|
232
|
+
# # 1
|
233
|
+
# # 1
|
234
|
+
# # 2
|
235
|
+
# # ]
|
236
|
+
def quarter
|
237
|
+
super
|
238
|
+
end
|
239
|
+
|
240
|
+
# Extract the month from the underlying date representation.
|
241
|
+
#
|
242
|
+
# Applies to Date and Datetime columns.
|
243
|
+
#
|
244
|
+
# Returns the month number starting from 1.
|
245
|
+
# The return value ranges from 1 to 12.
|
246
|
+
#
|
247
|
+
# @return [Series]
|
248
|
+
#
|
249
|
+
# @example
|
250
|
+
# start = DateTime.new(2001, 1, 1)
|
251
|
+
# stop = DateTime.new(2001, 4, 1)
|
252
|
+
# date = Polars.date_range(start, stop, "1mo")
|
253
|
+
# # =>
|
254
|
+
# # shape: (4,)
|
255
|
+
# # Series: '' [datetime[μs]]
|
256
|
+
# # [
|
257
|
+
# # 2001-01-01 00:00:00
|
258
|
+
# # 2001-02-01 00:00:00
|
259
|
+
# # 2001-03-01 00:00:00
|
260
|
+
# # 2001-04-01 00:00:00
|
261
|
+
# # ]
|
262
|
+
#
|
263
|
+
# @example
|
264
|
+
# date.dt.month
|
265
|
+
# # =>
|
266
|
+
# # shape: (4,)
|
267
|
+
# # Series: '' [u32]
|
268
|
+
# # [
|
269
|
+
# # 1
|
270
|
+
# # 2
|
271
|
+
# # 3
|
272
|
+
# # 4
|
273
|
+
# # ]
|
274
|
+
def month
|
275
|
+
super
|
276
|
+
end
|
277
|
+
|
278
|
+
# Extract the week from the underlying date representation.
|
279
|
+
#
|
280
|
+
# Applies to Date and Datetime columns.
|
281
|
+
#
|
282
|
+
# Returns the ISO week number starting from 1.
|
283
|
+
# The return value ranges from 1 to 53. (The last week of year differs by years.)
|
284
|
+
#
|
285
|
+
# @return [Series]
|
286
|
+
#
|
287
|
+
# @example
|
288
|
+
# start = DateTime.new(2001, 1, 1)
|
289
|
+
# stop = DateTime.new(2001, 4, 1)
|
290
|
+
# date = Polars.date_range(start, stop, "1mo")
|
291
|
+
# # =>
|
292
|
+
# # shape: (4,)
|
293
|
+
# # Series: '' [datetime[μs]]
|
294
|
+
# # [
|
295
|
+
# # 2001-01-01 00:00:00
|
296
|
+
# # 2001-02-01 00:00:00
|
297
|
+
# # 2001-03-01 00:00:00
|
298
|
+
# # 2001-04-01 00:00:00
|
299
|
+
# # ]
|
300
|
+
#
|
301
|
+
# @example
|
302
|
+
# date.dt.week
|
303
|
+
# # =>
|
304
|
+
# # shape: (4,)
|
305
|
+
# # Series: '' [u32]
|
306
|
+
# # [
|
307
|
+
# # 1
|
308
|
+
# # 5
|
309
|
+
# # 9
|
310
|
+
# # 13
|
311
|
+
# # ]
|
312
|
+
def week
|
313
|
+
super
|
314
|
+
end
|
315
|
+
|
316
|
+
# Extract the week day from the underlying date representation.
|
317
|
+
#
|
318
|
+
# Applies to Date and Datetime columns.
|
319
|
+
#
|
320
|
+
# Returns the ISO weekday number where monday = 1 and sunday = 7
|
321
|
+
#
|
322
|
+
# @return [Series]
|
323
|
+
#
|
324
|
+
# @example
|
325
|
+
# start = DateTime.new(2001, 1, 1)
|
326
|
+
# stop = DateTime.new(2001, 1, 7)
|
327
|
+
# date = Polars.date_range(start, stop, "1d")
|
328
|
+
# # =>
|
329
|
+
# # shape: (7,)
|
330
|
+
# # Series: '' [datetime[μs]]
|
331
|
+
# # [
|
332
|
+
# # 2001-01-01 00:00:00
|
333
|
+
# # 2001-01-02 00:00:00
|
334
|
+
# # 2001-01-03 00:00:00
|
335
|
+
# # 2001-01-04 00:00:00
|
336
|
+
# # 2001-01-05 00:00:00
|
337
|
+
# # 2001-01-06 00:00:00
|
338
|
+
# # 2001-01-07 00:00:00
|
339
|
+
# # ]
|
340
|
+
#
|
341
|
+
# @example
|
342
|
+
# date.dt.weekday
|
343
|
+
# # =>
|
344
|
+
# # shape: (7,)
|
345
|
+
# # Series: '' [u32]
|
346
|
+
# # [
|
347
|
+
# # 1
|
348
|
+
# # 2
|
349
|
+
# # 3
|
350
|
+
# # 4
|
351
|
+
# # 5
|
352
|
+
# # 6
|
353
|
+
# # 7
|
354
|
+
# # ]
|
355
|
+
def weekday
|
356
|
+
super
|
357
|
+
end
|
358
|
+
|
359
|
+
# Extract the day from the underlying date representation.
|
360
|
+
#
|
361
|
+
# Applies to Date and Datetime columns.
|
362
|
+
#
|
363
|
+
# Returns the day of month starting from 1.
|
364
|
+
# The return value ranges from 1 to 31. (The last day of month differs by months.)
|
365
|
+
#
|
366
|
+
# @return [Series]
|
367
|
+
#
|
368
|
+
# @example
|
369
|
+
# start = DateTime.new(2001, 1, 1)
|
370
|
+
# stop = DateTime.new(2001, 1, 9)
|
371
|
+
# date = Polars.date_range(start, stop, "2d")
|
372
|
+
# # =>
|
373
|
+
# # shape: (5,)
|
374
|
+
# # Series: '' [datetime[μs]]
|
375
|
+
# # [
|
376
|
+
# # 2001-01-01 00:00:00
|
377
|
+
# # 2001-01-03 00:00:00
|
378
|
+
# # 2001-01-05 00:00:00
|
379
|
+
# # 2001-01-07 00:00:00
|
380
|
+
# # 2001-01-09 00:00:00
|
381
|
+
# # ]
|
382
|
+
#
|
383
|
+
# @example
|
384
|
+
# date.dt.day
|
385
|
+
# # =>
|
386
|
+
# # shape: (5,)
|
387
|
+
# # Series: '' [u32]
|
388
|
+
# # [
|
389
|
+
# # 1
|
390
|
+
# # 3
|
391
|
+
# # 5
|
392
|
+
# # 7
|
393
|
+
# # 9
|
394
|
+
# # ]
|
395
|
+
def day
|
396
|
+
super
|
397
|
+
end
|
398
|
+
|
399
|
+
# Extract ordinal day from underlying date representation.
|
400
|
+
#
|
401
|
+
# Applies to Date and Datetime columns.
|
402
|
+
#
|
403
|
+
# Returns the day of year starting from 1.
|
404
|
+
# The return value ranges from 1 to 366. (The last day of year differs by years.)
|
405
|
+
#
|
406
|
+
# @return [Series]
|
407
|
+
#
|
408
|
+
# @example
|
409
|
+
# start = DateTime.new(2001, 1, 1)
|
410
|
+
# stop = DateTime.new(2001, 3, 1)
|
411
|
+
# date = Polars.date_range(start, stop, "1mo")
|
412
|
+
# # =>
|
413
|
+
# # shape: (3,)
|
414
|
+
# # Series: '' [datetime[μs]]
|
415
|
+
# # [
|
416
|
+
# # 2001-01-01 00:00:00
|
417
|
+
# # 2001-02-01 00:00:00
|
418
|
+
# # 2001-03-01 00:00:00
|
419
|
+
# # ]
|
420
|
+
#
|
421
|
+
# @example
|
422
|
+
# date.dt.ordinal_day
|
423
|
+
# # =>
|
424
|
+
# # shape: (3,)
|
425
|
+
# # Series: '' [u32]
|
426
|
+
# # [
|
427
|
+
# # 1
|
428
|
+
# # 32
|
429
|
+
# # 60
|
430
|
+
# # ]
|
431
|
+
def ordinal_day
|
432
|
+
super
|
433
|
+
end
|
434
|
+
|
435
|
+
# Extract the hour from the underlying DateTime representation.
|
436
|
+
#
|
437
|
+
# Applies to Datetime columns.
|
438
|
+
#
|
439
|
+
# Returns the hour number from 0 to 23.
|
440
|
+
#
|
441
|
+
# @return [Series]
|
442
|
+
#
|
443
|
+
# @example
|
444
|
+
# start = DateTime.new(2001, 1, 1)
|
445
|
+
# stop = DateTime.new(2001, 1, 1, 3)
|
446
|
+
# date = Polars.date_range(start, stop, "1h")
|
447
|
+
# # =>
|
448
|
+
# # shape: (4,)
|
449
|
+
# # Series: '' [datetime[μs]]
|
450
|
+
# # [
|
451
|
+
# # 2001-01-01 00:00:00
|
452
|
+
# # 2001-01-01 01:00:00
|
453
|
+
# # 2001-01-01 02:00:00
|
454
|
+
# # 2001-01-01 03:00:00
|
455
|
+
# # ]
|
456
|
+
#
|
457
|
+
# @example
|
458
|
+
# date.dt.hour
|
459
|
+
# # =>
|
460
|
+
# # shape: (4,)
|
461
|
+
# # Series: '' [u32]
|
462
|
+
# # [
|
463
|
+
# # 0
|
464
|
+
# # 1
|
465
|
+
# # 2
|
466
|
+
# # 3
|
467
|
+
# # ]
|
468
|
+
def hour
|
469
|
+
super
|
470
|
+
end
|
471
|
+
|
472
|
+
# Extract the minutes from the underlying DateTime representation.
|
473
|
+
#
|
474
|
+
# Applies to Datetime columns.
|
475
|
+
#
|
476
|
+
# Returns the minute number from 0 to 59.
|
477
|
+
#
|
478
|
+
# @return [Series]
|
479
|
+
#
|
480
|
+
# @example
|
481
|
+
# start = DateTime.new(2001, 1, 1)
|
482
|
+
# stop = DateTime.new(2001, 1, 1, 0, 4, 0)
|
483
|
+
# date = Polars.date_range(start, stop, "2m")
|
484
|
+
# # =>
|
485
|
+
# # shape: (3,)
|
486
|
+
# # Series: '' [datetime[μs]]
|
487
|
+
# # [
|
488
|
+
# # 2001-01-01 00:00:00
|
489
|
+
# # 2001-01-01 00:02:00
|
490
|
+
# # 2001-01-01 00:04:00
|
491
|
+
# # ]
|
492
|
+
#
|
493
|
+
# @example
|
494
|
+
# date.dt.minute
|
495
|
+
# # =>
|
496
|
+
# # shape: (3,)
|
497
|
+
# # Series: '' [u32]
|
498
|
+
# # [
|
499
|
+
# # 0
|
500
|
+
# # 2
|
501
|
+
# # 4
|
502
|
+
# # ]
|
503
|
+
def minute
|
504
|
+
super
|
505
|
+
end
|
506
|
+
|
507
|
+
# Extract seconds from underlying DateTime representation.
|
508
|
+
#
|
509
|
+
# Applies to Datetime columns.
|
510
|
+
#
|
511
|
+
# Returns the integer second number from 0 to 59, or a floating
|
512
|
+
# point number from 0 < 60 if `fractional: true` that includes
|
513
|
+
# any milli/micro/nanosecond component.
|
514
|
+
#
|
515
|
+
# @return [Series]
|
516
|
+
#
|
517
|
+
# @example
|
518
|
+
# start = DateTime.new(2001, 1, 1)
|
519
|
+
# stop = DateTime.new(2001, 1, 1, 0, 0, 4)
|
520
|
+
# date = Polars.date_range(start, stop, "500ms")
|
521
|
+
# # =>
|
522
|
+
# # shape: (9,)
|
523
|
+
# # Series: '' [datetime[μs]]
|
524
|
+
# # [
|
525
|
+
# # 2001-01-01 00:00:00
|
526
|
+
# # 2001-01-01 00:00:00.500
|
527
|
+
# # 2001-01-01 00:00:01
|
528
|
+
# # 2001-01-01 00:00:01.500
|
529
|
+
# # 2001-01-01 00:00:02
|
530
|
+
# # 2001-01-01 00:00:02.500
|
531
|
+
# # 2001-01-01 00:00:03
|
532
|
+
# # 2001-01-01 00:00:03.500
|
533
|
+
# # 2001-01-01 00:00:04
|
534
|
+
# # ]
|
535
|
+
#
|
536
|
+
# @example
|
537
|
+
# date.dt.second
|
538
|
+
# # =>
|
539
|
+
# # shape: (9,)
|
540
|
+
# # Series: '' [u32]
|
541
|
+
# # [
|
542
|
+
# # 0
|
543
|
+
# # 0
|
544
|
+
# # 1
|
545
|
+
# # 1
|
546
|
+
# # 2
|
547
|
+
# # 2
|
548
|
+
# # 3
|
549
|
+
# # 3
|
550
|
+
# # 4
|
551
|
+
# # ]
|
552
|
+
#
|
553
|
+
# @example
|
554
|
+
# date.dt.second(fractional: true)
|
555
|
+
# # =>
|
556
|
+
# # shape: (9,)
|
557
|
+
# # Series: '' [f64]
|
558
|
+
# # [
|
559
|
+
# # 0.0
|
560
|
+
# # 0.5
|
561
|
+
# # 1.0
|
562
|
+
# # 1.5
|
563
|
+
# # 2.0
|
564
|
+
# # 2.5
|
565
|
+
# # 3.0
|
566
|
+
# # 3.5
|
567
|
+
# # 4.0
|
568
|
+
# # ]
|
569
|
+
def second(fractional: false)
|
570
|
+
super
|
571
|
+
end
|
572
|
+
|
573
|
+
# Extract the milliseconds from the underlying DateTime representation.
|
574
|
+
#
|
575
|
+
# Applies to Datetime columns.
|
576
|
+
#
|
577
|
+
# @return [Series]
|
578
|
+
#
|
579
|
+
# @example
|
580
|
+
# start = DateTime.new(2001, 1, 1)
|
581
|
+
# stop = DateTime.new(2001, 1, 1, 0, 0, 4)
|
582
|
+
# date = Polars.date_range(start, stop, "500ms")
|
583
|
+
# # =>
|
584
|
+
# # shape: (9,)
|
585
|
+
# # Series: '' [datetime[μs]]
|
586
|
+
# # [
|
587
|
+
# # 2001-01-01 00:00:00
|
588
|
+
# # 2001-01-01 00:00:00.500
|
589
|
+
# # 2001-01-01 00:00:01
|
590
|
+
# # 2001-01-01 00:00:01.500
|
591
|
+
# # 2001-01-01 00:00:02
|
592
|
+
# # 2001-01-01 00:00:02.500
|
593
|
+
# # 2001-01-01 00:00:03
|
594
|
+
# # 2001-01-01 00:00:03.500
|
595
|
+
# # 2001-01-01 00:00:04
|
596
|
+
# # ]
|
597
|
+
#
|
598
|
+
# @example
|
599
|
+
# date.dt.millisecond
|
600
|
+
# # =>
|
601
|
+
# # shape: (9,)
|
602
|
+
# # Series: '' [u32]
|
603
|
+
# # [
|
604
|
+
# # 0
|
605
|
+
# # 500
|
606
|
+
# # 0
|
607
|
+
# # 500
|
608
|
+
# # 0
|
609
|
+
# # 500
|
610
|
+
# # 0
|
611
|
+
# # 500
|
612
|
+
# # 0
|
613
|
+
# # ]
|
614
|
+
def millisecond
|
615
|
+
super
|
616
|
+
end
|
617
|
+
|
618
|
+
# Extract the microseconds from the underlying DateTime representation.
|
619
|
+
#
|
620
|
+
# Applies to Datetime columns.
|
621
|
+
#
|
622
|
+
# @return [Series]
|
623
|
+
#
|
624
|
+
# @example
|
625
|
+
# start = DateTime.new(2001, 1, 1)
|
626
|
+
# stop = DateTime.new(2001, 1, 1, 0, 0, 4)
|
627
|
+
# date = Polars.date_range(start, stop, "500ms")
|
628
|
+
# # =>
|
629
|
+
# # shape: (9,)
|
630
|
+
# # Series: '' [datetime[μs]]
|
631
|
+
# # [
|
632
|
+
# # 2001-01-01 00:00:00
|
633
|
+
# # 2001-01-01 00:00:00.500
|
634
|
+
# # 2001-01-01 00:00:01
|
635
|
+
# # 2001-01-01 00:00:01.500
|
636
|
+
# # 2001-01-01 00:00:02
|
637
|
+
# # 2001-01-01 00:00:02.500
|
638
|
+
# # 2001-01-01 00:00:03
|
639
|
+
# # 2001-01-01 00:00:03.500
|
640
|
+
# # 2001-01-01 00:00:04
|
641
|
+
# # ]
|
642
|
+
#
|
643
|
+
# @example
|
644
|
+
# date.dt.microsecond
|
645
|
+
# # =>
|
646
|
+
# # shape: (9,)
|
647
|
+
# # Series: '' [u32]
|
648
|
+
# # [
|
649
|
+
# # 0
|
650
|
+
# # 500000
|
651
|
+
# # 0
|
652
|
+
# # 500000
|
653
|
+
# # 0
|
654
|
+
# # 500000
|
655
|
+
# # 0
|
656
|
+
# # 500000
|
657
|
+
# # 0
|
658
|
+
# # ]
|
659
|
+
def microsecond
|
660
|
+
super
|
661
|
+
end
|
662
|
+
|
663
|
+
# Extract the nanoseconds from the underlying DateTime representation.
|
664
|
+
#
|
665
|
+
# Applies to Datetime columns.
|
666
|
+
#
|
667
|
+
# @return [Series]
|
668
|
+
#
|
669
|
+
# @example
|
670
|
+
# start = DateTime.new(2001, 1, 1)
|
671
|
+
# stop = DateTime.new(2001, 1, 1, 0, 0, 4)
|
672
|
+
# date = Polars.date_range(start, stop, "500ms")
|
673
|
+
# # =>
|
674
|
+
# # shape: (9,)
|
675
|
+
# # Series: '' [datetime[μs]]
|
676
|
+
# # [
|
677
|
+
# # 2001-01-01 00:00:00
|
678
|
+
# # 2001-01-01 00:00:00.500
|
679
|
+
# # 2001-01-01 00:00:01
|
680
|
+
# # 2001-01-01 00:00:01.500
|
681
|
+
# # 2001-01-01 00:00:02
|
682
|
+
# # 2001-01-01 00:00:02.500
|
683
|
+
# # 2001-01-01 00:00:03
|
684
|
+
# # 2001-01-01 00:00:03.500
|
685
|
+
# # 2001-01-01 00:00:04
|
686
|
+
# # ]
|
687
|
+
#
|
688
|
+
# @example
|
689
|
+
# date.dt.nanosecond
|
690
|
+
# # =>
|
691
|
+
# # shape: (9,)
|
692
|
+
# # Series: '' [u32]
|
693
|
+
# # [
|
694
|
+
# # 0
|
695
|
+
# # 500000000
|
696
|
+
# # 0
|
697
|
+
# # 500000000
|
698
|
+
# # 0
|
699
|
+
# # 500000000
|
700
|
+
# # 0
|
701
|
+
# # 500000000
|
702
|
+
# # 0
|
703
|
+
# # ]
|
704
|
+
def nanosecond
|
705
|
+
super
|
706
|
+
end
|
707
|
+
|
708
|
+
# Return a timestamp in the given time unit.
|
709
|
+
#
|
710
|
+
# @param tu ["us", "ns", "ms"]
|
711
|
+
# Time unit.
|
712
|
+
#
|
713
|
+
# @return [Series]
|
714
|
+
#
|
715
|
+
# @example
|
716
|
+
# start = DateTime.new(2001, 1, 1)
|
717
|
+
# stop = DateTime.new(2001, 1, 3)
|
718
|
+
# date = Polars.date_range(start, stop, "1d")
|
719
|
+
# # =>
|
720
|
+
# # shape: (3,)
|
721
|
+
# # Series: '' [datetime[μs]]
|
722
|
+
# # [
|
723
|
+
# # 2001-01-01 00:00:00
|
724
|
+
# # 2001-01-02 00:00:00
|
725
|
+
# # 2001-01-03 00:00:00
|
726
|
+
# # ]
|
727
|
+
#
|
728
|
+
# @example
|
729
|
+
# date.dt.timestamp.alias("timestamp_us")
|
730
|
+
# # =>
|
731
|
+
# # shape: (3,)
|
732
|
+
# # Series: 'timestamp_us' [i64]
|
733
|
+
# # [
|
734
|
+
# # 978307200000000
|
735
|
+
# # 978393600000000
|
736
|
+
# # 978480000000000
|
737
|
+
# # ]
|
738
|
+
#
|
739
|
+
# @example
|
740
|
+
# date.dt.timestamp("ns").alias("timestamp_ns")
|
741
|
+
# # =>
|
742
|
+
# # shape: (3,)
|
743
|
+
# # Series: 'timestamp_ns' [i64]
|
744
|
+
# # [
|
745
|
+
# # 978307200000000000
|
746
|
+
# # 978393600000000000
|
747
|
+
# # 978480000000000000
|
748
|
+
# # ]
|
749
|
+
def timestamp(tu = "us")
|
750
|
+
super
|
751
|
+
end
|
752
|
+
|
753
|
+
# Get the time passed since the Unix EPOCH in the give time unit.
|
754
|
+
#
|
755
|
+
# @param tu ["us", "ns", "ms", "s", "d"]
|
756
|
+
# Time unit.
|
757
|
+
#
|
758
|
+
# @return [Series]
|
759
|
+
#
|
760
|
+
# @example
|
761
|
+
# start = DateTime.new(2001, 1, 1)
|
762
|
+
# stop = DateTime.new(2001, 1, 3)
|
763
|
+
# date = Polars.date_range(start, stop, "1d")
|
764
|
+
# # =>
|
765
|
+
# # shape: (3,)
|
766
|
+
# # Series: '' [datetime[μs]]
|
767
|
+
# # [
|
768
|
+
# # 2001-01-01 00:00:00
|
769
|
+
# # 2001-01-02 00:00:00
|
770
|
+
# # 2001-01-03 00:00:00
|
771
|
+
# # ]
|
772
|
+
#
|
773
|
+
# @example
|
774
|
+
# date.dt.epoch.alias("epoch_ns")
|
775
|
+
# # =>
|
776
|
+
# # shape: (3,)
|
777
|
+
# # Series: 'epoch_ns' [i64]
|
778
|
+
# # [
|
779
|
+
# # 978307200000000
|
780
|
+
# # 978393600000000
|
781
|
+
# # 978480000000000
|
782
|
+
# # ]
|
783
|
+
#
|
784
|
+
# @example
|
785
|
+
# date.dt.epoch("s").alias("epoch_s")
|
786
|
+
# # =>
|
787
|
+
# # shape: (3,)
|
788
|
+
# # Series: 'epoch_s' [i64]
|
789
|
+
# # [
|
790
|
+
# # 978307200
|
791
|
+
# # 978393600
|
792
|
+
# # 978480000
|
793
|
+
# # ]
|
794
|
+
def epoch(tu = "us")
|
795
|
+
super
|
796
|
+
end
|
797
|
+
|
798
|
+
# Set time unit a Series of dtype Datetime or Duration.
|
799
|
+
#
|
800
|
+
# This does not modify underlying data, and should be used to fix an incorrect
|
801
|
+
# time unit.
|
802
|
+
#
|
803
|
+
# @param tu ["ns", "us", "ms"]
|
804
|
+
# Time unit for the `Datetime` Series.
|
805
|
+
#
|
806
|
+
# @return [Series]
|
807
|
+
#
|
808
|
+
# @example
|
809
|
+
# start = DateTime.new(2001, 1, 1)
|
810
|
+
# stop = DateTime.new(2001, 1, 3)
|
811
|
+
# date = Polars.date_range(start, stop, "1d", time_unit: "ns")
|
812
|
+
# # =>
|
813
|
+
# # shape: (3,)
|
814
|
+
# # Series: '' [datetime[ns]]
|
815
|
+
# # [
|
816
|
+
# # 2001-01-01 00:00:00
|
817
|
+
# # 2001-01-02 00:00:00
|
818
|
+
# # 2001-01-03 00:00:00
|
819
|
+
# # ]
|
820
|
+
#
|
821
|
+
# @example
|
822
|
+
# date.dt.with_time_unit("us").alias("tu_us")
|
823
|
+
# # =>
|
824
|
+
# # shape: (3,)
|
825
|
+
# # Series: 'tu_us' [datetime[μs]]
|
826
|
+
# # [
|
827
|
+
# # +32971-04-28 00:00:00
|
828
|
+
# # +32974-01-22 00:00:00
|
829
|
+
# # +32976-10-18 00:00:00
|
830
|
+
# # ]
|
831
|
+
def with_time_unit(tu)
|
832
|
+
super
|
833
|
+
end
|
834
|
+
|
835
|
+
# Cast the underlying data to another time unit. This may lose precision.
|
836
|
+
#
|
837
|
+
# @param tu ["ns", "us", "ms"]
|
838
|
+
# Time unit for the `Datetime` Series.
|
839
|
+
#
|
840
|
+
# @return [Series]
|
841
|
+
#
|
842
|
+
# @example
|
843
|
+
# start = DateTime.new(2001, 1, 1)
|
844
|
+
# stop = DateTime.new(2001, 1, 3)
|
845
|
+
# date = Polars.date_range(start, stop, "1d")
|
846
|
+
# # =>
|
847
|
+
# # shape: (3,)
|
848
|
+
# # Series: '' [datetime[μs]]
|
849
|
+
# # [
|
850
|
+
# # 2001-01-01 00:00:00
|
851
|
+
# # 2001-01-02 00:00:00
|
852
|
+
# # 2001-01-03 00:00:00
|
853
|
+
# # ]
|
854
|
+
#
|
855
|
+
# @example
|
856
|
+
# date.dt.cast_time_unit("ms").alias("tu_ms")
|
857
|
+
# # =>
|
858
|
+
# # shape: (3,)
|
859
|
+
# # Series: 'tu_ms' [datetime[ms]]
|
860
|
+
# # [
|
861
|
+
# # 2001-01-01 00:00:00
|
862
|
+
# # 2001-01-02 00:00:00
|
863
|
+
# # 2001-01-03 00:00:00
|
864
|
+
# # ]
|
865
|
+
#
|
866
|
+
# @example
|
867
|
+
# date.dt.cast_time_unit("ns").alias("tu_ns")
|
868
|
+
# # =>
|
869
|
+
# # shape: (3,)
|
870
|
+
# # Series: 'tu_ns' [datetime[ns]]
|
871
|
+
# # [
|
872
|
+
# # 2001-01-01 00:00:00
|
873
|
+
# # 2001-01-02 00:00:00
|
874
|
+
# # 2001-01-03 00:00:00
|
875
|
+
# # ]
|
876
|
+
def cast_time_unit(tu)
|
877
|
+
super
|
878
|
+
end
|
879
|
+
|
880
|
+
# Set time zone a Series of type Datetime.
|
881
|
+
#
|
882
|
+
# @param tz [String]
|
883
|
+
# Time zone for the `Datetime` Series.
|
884
|
+
#
|
885
|
+
# @return [Series]
|
886
|
+
#
|
887
|
+
# @example
|
888
|
+
# start = DateTime.new(2020, 3, 1)
|
889
|
+
# stop = DateTime.new(2020, 5, 1)
|
890
|
+
# date = Polars.date_range(start, stop, "1mo")
|
891
|
+
# # =>
|
892
|
+
# # shape: (3,)
|
893
|
+
# # Series: '' [datetime[μs]]
|
894
|
+
# # [
|
895
|
+
# # 2020-03-01 00:00:00
|
896
|
+
# # 2020-04-01 00:00:00
|
897
|
+
# # 2020-05-01 00:00:00
|
898
|
+
# # ]
|
899
|
+
#
|
900
|
+
# @example
|
901
|
+
# date.dt.with_time_zone("Europe/London").alias("London")
|
902
|
+
# # =>
|
903
|
+
# # shape: (3,)
|
904
|
+
# # Series: 'London' [datetime[μs, Europe/London]]
|
905
|
+
# # [
|
906
|
+
# # 2020-03-01 00:00:00 GMT
|
907
|
+
# # 2020-04-01 01:00:00 BST
|
908
|
+
# # 2020-05-01 01:00:00 BST
|
909
|
+
# # ]
|
910
|
+
def with_time_zone(tz)
|
911
|
+
super
|
912
|
+
end
|
913
|
+
|
914
|
+
# Cast time zone for a Series of type Datetime.
|
915
|
+
#
|
916
|
+
# Different from `with_time_zone`, this will also modify
|
917
|
+
# the underlying timestamp.
|
918
|
+
#
|
919
|
+
# @param tz [String]
|
920
|
+
# Time zone for the `Datetime` Series.
|
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")
|
928
|
+
# # =>
|
929
|
+
# # shape: (3,)
|
930
|
+
# # Series: '' [datetime[μs]]
|
931
|
+
# # [
|
932
|
+
# # 2020-03-01 00:00:00
|
933
|
+
# # 2020-04-01 00:00:00
|
934
|
+
# # 2020-05-01 00:00:00
|
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.with_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 with_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.cast_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 cast_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 cast_time_zone(tz)
|
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)
|
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
|