datetime.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cudf/types.hpp>
20 
21 #include <rmm/mr/device/per_device_resource.hpp>
22 #include <rmm/resource_ref.hpp>
23 
24 #include <memory>
25 
31 namespace cudf {
32 namespace datetime {
49 std::unique_ptr<cudf::column> extract_year(
51  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
52 
63 std::unique_ptr<cudf::column> extract_month(
65  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
66 
77 std::unique_ptr<cudf::column> extract_day(
79  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
80 
91 std::unique_ptr<cudf::column> extract_weekday(
93  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
94 
105 std::unique_ptr<cudf::column> extract_hour(
106  cudf::column_view const& column,
107  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
108 
119 std::unique_ptr<cudf::column> extract_minute(
120  cudf::column_view const& column,
121  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
122 
133 std::unique_ptr<cudf::column> extract_second(
134  cudf::column_view const& column,
135  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
136 
150 std::unique_ptr<cudf::column> extract_millisecond_fraction(
151  cudf::column_view const& column,
152  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
153 
167 std::unique_ptr<cudf::column> extract_microsecond_fraction(
168  cudf::column_view const& column,
169  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
170 
184 std::unique_ptr<cudf::column> extract_nanosecond_fraction(
185  cudf::column_view const& column,
186  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
187  // end of group
205 std::unique_ptr<cudf::column> last_day_of_month(
206  cudf::column_view const& column,
207  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
208 
219 std::unique_ptr<cudf::column> day_of_year(
220  cudf::column_view const& column,
221  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
222 
253 std::unique_ptr<cudf::column> add_calendrical_months(
254  cudf::column_view const& timestamps,
255  cudf::column_view const& months,
256  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
257 
288 std::unique_ptr<cudf::column> add_calendrical_months(
289  cudf::column_view const& timestamps,
290  cudf::scalar const& months,
291  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
292 
306 std::unique_ptr<cudf::column> is_leap_year(
307  cudf::column_view const& column,
308  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
309 
322 std::unique_ptr<cudf::column> days_in_month(
323  cudf::column_view const& column,
324  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
325 
338 std::unique_ptr<cudf::column> extract_quarter(
339  cudf::column_view const& column,
340  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
341 
346 enum class rounding_frequency : int32_t {
347  DAY,
348  HOUR,
349  MINUTE,
350  SECOND,
351  MILLISECOND,
352  MICROSECOND,
353  NANOSECOND
354 };
355 
366 std::unique_ptr<cudf::column> ceil_datetimes(
367  cudf::column_view const& column,
368  rounding_frequency freq,
369  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
370 
381 std::unique_ptr<cudf::column> floor_datetimes(
382  cudf::column_view const& column,
383  rounding_frequency freq,
384  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
385 
396 std::unique_ptr<cudf::column> round_datetimes(
397  cudf::column_view const& column,
398  rounding_frequency freq,
399  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
400  // end of group
402 
403 } // namespace datetime
404 } // namespace cudf
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
A container of nullable device data as a column of elements.
Definition: column.hpp:48
An owning class to represent a singular value.
Definition: scalar.hpp:49
std::unique_ptr< cudf::column > extract_quarter(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Returns the quarter of the date.
std::unique_ptr< cudf::column > add_calendrical_months(cudf::column_view const &timestamps, cudf::scalar const &months, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Adds or subtracts a number of months from the datetime type and returns a timestamp column that is of...
std::unique_ptr< cudf::column > floor_datetimes(cudf::column_view const &column, rounding_frequency freq, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Round datetimes down to the nearest multiple of the given frequency.
std::unique_ptr< cudf::column > round_datetimes(cudf::column_view const &column, rounding_frequency freq, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Round datetimes to the nearest multiple of the given frequency.
std::unique_ptr< cudf::column > ceil_datetimes(cudf::column_view const &column, rounding_frequency freq, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Round datetimes up to the nearest multiple of the given frequency.
std::unique_ptr< cudf::column > is_leap_year(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Check if the year of the given date is a leap year.
std::unique_ptr< cudf::column > days_in_month(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extract the number of days in the month.
std::unique_ptr< cudf::column > day_of_year(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Computes the day number since the start of the year from the datetime and returns an int16_t cudf::co...
rounding_frequency
Fixed frequencies supported by datetime rounding functions ceil, floor, round.
Definition: datetime.hpp:346
std::unique_ptr< cudf::column > last_day_of_month(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Computes the last day of the month in datetime type and returns a TIMESTAMP_DAYS cudf::column.
std::unique_ptr< cudf::column > extract_microsecond_fraction(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts microsecond fraction from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_nanosecond_fraction(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts nanosecond fraction from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_minute(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts minute from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_millisecond_fraction(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts millisecond fraction from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_year(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts year from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_day(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts day from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_month(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts month from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_weekday(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts a weekday from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_second(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts second from any datetime type and returns an int16_t cudf::column.
std::unique_ptr< cudf::column > extract_hour(cudf::column_view const &column, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Extracts hour from any datetime type and returns an int16_t cudf::column.
cuDF interfaces
Definition: aggregation.hpp:34
Type declarations for libcudf.