1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! `Series` datetime namespace for GPU datetime operations.
use super::{context::SeriesOps, owned::Series};
use crate::{core::error::Result, ops::datetime::DatetimeComponent, runtime::Exec};
impl<'a> SeriesOps<'a> {
/// Enter the datetime namespace for timestamp-specific series methods.
pub fn dt(&self) -> SeriesDatetimeOps<'a> {
SeriesDatetimeOps { series: self.series, ctx: self.ctx }
}
}
/// Datetime operations of one [`Series`], run where an [`Exec`] selects.
#[must_use]
pub struct SeriesDatetimeOps<'a> {
series: &'a Series,
ctx: Exec<'a>,
}
impl SeriesDatetimeOps<'_> {
/// Extract the calendar year as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements.
///
/// Equivalent to cuDF Python's `Series.dt.year`.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn year(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Year, self.ctx, "series::dt::year")
}
/// Extract the calendar month as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements. Months are one-based.
///
/// Equivalent to cuDF Python's `Series.dt.month`.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn month(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Month, self.ctx, "series::dt::month")
}
/// Extract the day of month as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements. Days are one-based.
///
/// Equivalent to cuDF Python's `Series.dt.day`.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn day(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Day, self.ctx, "series::dt::day")
}
/// Extract the hour of the day as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements. Hours range from 0 through 23.
///
/// Equivalent to cuDF Python's `Series.dt.hour`.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn hour(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Hour, self.ctx, "series::dt::hour")
}
/// Extract the minute of the hour as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements. Minutes range from 0 through 59.
///
/// Equivalent to cuDF Python's `Series.dt.minute`.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn minute(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Minute, self.ctx, "series::dt::minute")
}
/// Extract the second of the minute as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements. Seconds range from 0 through 59.
///
/// Equivalent to cuDF Python's `Series.dt.second`.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn second(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Second, self.ctx, "series::dt::second")
}
/// Extract the millisecond segment within the second as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements. Values range from 0 through 999 and are not a total of
/// milliseconds since midnight.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn millisecond(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Millisecond, self.ctx, "series::dt::millisecond")
}
/// Extract the microsecond segment within the millisecond as an `INT16` Series.
///
/// The input must be timestamp typed. Null input elements produce null
/// output elements. Values range from 0 through 999 and are not a total of
/// microseconds since midnight.
///
/// Equivalent to cuDF Python's `Series.dt.microsecond`.
///
/// # Cost
/// Allocates a new `INT16` device column.
pub fn microsecond(&self) -> Result<Series> {
self.series.datetime_component_with_context(DatetimeComponent::Microsecond, self.ctx, "series::dt::microsecond")
}
}