polars_python/expr/
datetime.rs1use polars::prelude::*;
2use pyo3::prelude::*;
3
4use crate::conversion::Wrap;
5use crate::PyExpr;
6
7#[pymethods]
8impl PyExpr {
9 fn dt_add_business_days(
10 &self,
11 n: PyExpr,
12 week_mask: [bool; 7],
13 holidays: Vec<i32>,
14 roll: Wrap<Roll>,
15 ) -> Self {
16 self.inner
17 .clone()
18 .dt()
19 .add_business_days(n.inner, week_mask, holidays, roll.0)
20 .into()
21 }
22
23 fn dt_to_string(&self, format: &str) -> Self {
24 self.inner.clone().dt().to_string(format).into()
25 }
26
27 fn dt_offset_by(&self, by: PyExpr) -> Self {
28 self.inner.clone().dt().offset_by(by.inner).into()
29 }
30
31 fn dt_epoch_seconds(&self) -> Self {
32 self.inner
33 .clone()
34 .map(
35 |s| {
36 s.take_materialized_series()
37 .timestamp(TimeUnit::Milliseconds)
38 .map(|ca| Some((ca / 1000).into_column()))
39 },
40 GetOutput::from_type(DataType::Int64),
41 )
42 .into()
43 }
44
45 fn dt_with_time_unit(&self, time_unit: Wrap<TimeUnit>) -> Self {
46 self.inner.clone().dt().with_time_unit(time_unit.0).into()
47 }
48
49 #[cfg(feature = "timezones")]
50 fn dt_convert_time_zone(&self, time_zone: String) -> Self {
51 self.inner
52 .clone()
53 .dt()
54 .convert_time_zone(time_zone.into())
55 .into()
56 }
57
58 fn dt_cast_time_unit(&self, time_unit: Wrap<TimeUnit>) -> Self {
59 self.inner.clone().dt().cast_time_unit(time_unit.0).into()
60 }
61
62 #[cfg(feature = "timezones")]
63 #[pyo3(signature = (time_zone, ambiguous, non_existent))]
64 fn dt_replace_time_zone(
65 &self,
66 time_zone: Option<String>,
67 ambiguous: Self,
68 non_existent: Wrap<NonExistent>,
69 ) -> Self {
70 self.inner
71 .clone()
72 .dt()
73 .replace_time_zone(time_zone.map(|x| x.into()), ambiguous.inner, non_existent.0)
74 .into()
75 }
76
77 fn dt_truncate(&self, every: Self) -> Self {
78 self.inner.clone().dt().truncate(every.inner).into()
79 }
80
81 fn dt_month_start(&self) -> Self {
82 self.inner.clone().dt().month_start().into()
83 }
84
85 fn dt_month_end(&self) -> Self {
86 self.inner.clone().dt().month_end().into()
87 }
88
89 #[cfg(feature = "timezones")]
90 fn dt_base_utc_offset(&self) -> Self {
91 self.inner.clone().dt().base_utc_offset().into()
92 }
93 #[cfg(feature = "timezones")]
94 fn dt_dst_offset(&self) -> Self {
95 self.inner.clone().dt().dst_offset().into()
96 }
97
98 fn dt_round(&self, every: Self) -> Self {
99 self.inner.clone().dt().round(every.inner).into()
100 }
101
102 fn dt_replace(
103 &self,
104 year: Self,
105 month: Self,
106 day: Self,
107 hour: Self,
108 minute: Self,
109 second: Self,
110 microsecond: Self,
111 ambiguous: Self,
112 ) -> Self {
113 self.inner
114 .clone()
115 .dt()
116 .replace(
117 year.inner,
118 month.inner,
119 day.inner,
120 hour.inner,
121 minute.inner,
122 second.inner,
123 microsecond.inner,
124 ambiguous.inner,
125 )
126 .into()
127 }
128
129 fn dt_combine(&self, time: Self, time_unit: Wrap<TimeUnit>) -> Self {
130 self.inner
131 .clone()
132 .dt()
133 .combine(time.inner, time_unit.0)
134 .into()
135 }
136 fn dt_millennium(&self) -> Self {
137 self.inner.clone().dt().millennium().into()
138 }
139 fn dt_century(&self) -> Self {
140 self.inner.clone().dt().century().into()
141 }
142 fn dt_year(&self) -> Self {
143 self.inner.clone().dt().year().into()
144 }
145 fn dt_is_leap_year(&self) -> Self {
146 self.inner.clone().dt().is_leap_year().into()
147 }
148 fn dt_iso_year(&self) -> Self {
149 self.inner.clone().dt().iso_year().into()
150 }
151 fn dt_quarter(&self) -> Self {
152 self.inner.clone().dt().quarter().into()
153 }
154 fn dt_month(&self) -> Self {
155 self.inner.clone().dt().month().into()
156 }
157 fn dt_week(&self) -> Self {
158 self.inner.clone().dt().week().into()
159 }
160 fn dt_weekday(&self) -> Self {
161 self.inner.clone().dt().weekday().into()
162 }
163 fn dt_day(&self) -> Self {
164 self.inner.clone().dt().day().into()
165 }
166 fn dt_ordinal_day(&self) -> Self {
167 self.inner.clone().dt().ordinal_day().into()
168 }
169 fn dt_time(&self) -> Self {
170 self.inner.clone().dt().time().into()
171 }
172 fn dt_date(&self) -> Self {
173 self.inner.clone().dt().date().into()
174 }
175 fn dt_datetime(&self) -> Self {
176 self.inner.clone().dt().datetime().into()
177 }
178 fn dt_hour(&self) -> Self {
179 self.inner.clone().dt().hour().into()
180 }
181 fn dt_minute(&self) -> Self {
182 self.inner.clone().dt().minute().into()
183 }
184 fn dt_second(&self) -> Self {
185 self.inner.clone().dt().second().into()
186 }
187 fn dt_millisecond(&self) -> Self {
188 self.inner.clone().dt().millisecond().into()
189 }
190 fn dt_microsecond(&self) -> Self {
191 self.inner.clone().dt().microsecond().into()
192 }
193 fn dt_nanosecond(&self) -> Self {
194 self.inner.clone().dt().nanosecond().into()
195 }
196 fn dt_timestamp(&self, time_unit: Wrap<TimeUnit>) -> Self {
197 self.inner.clone().dt().timestamp(time_unit.0).into()
198 }
199 fn dt_total_days(&self) -> Self {
200 self.inner.clone().dt().total_days().into()
201 }
202 fn dt_total_hours(&self) -> Self {
203 self.inner.clone().dt().total_hours().into()
204 }
205 fn dt_total_minutes(&self) -> Self {
206 self.inner.clone().dt().total_minutes().into()
207 }
208 fn dt_total_seconds(&self) -> Self {
209 self.inner.clone().dt().total_seconds().into()
210 }
211 fn dt_total_milliseconds(&self) -> Self {
212 self.inner.clone().dt().total_milliseconds().into()
213 }
214 fn dt_total_microseconds(&self) -> Self {
215 self.inner.clone().dt().total_microseconds().into()
216 }
217 fn dt_total_nanoseconds(&self) -> Self {
218 self.inner.clone().dt().total_nanoseconds().into()
219 }
220}