Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Add nanosecond & microsecond to DatetimeProperties #11911

Merged
merged 67 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8ff8f95
fixes
galipremsagar Sep 18, 2022
ca58733
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 22, 2022
579b6b1
fix repr
galipremsagar Sep 23, 2022
c625018
fix
galipremsagar Sep 23, 2022
148d0f8
Update python/cudf/cudf/core/column/datetime.py
galipremsagar Sep 23, 2022
97debb2
flake 8
galipremsagar Sep 23, 2022
af4a94d
docs
galipremsagar Sep 23, 2022
2b26c15
more changes
galipremsagar Sep 23, 2022
87421b1
fix docstring
galipremsagar Sep 23, 2022
cf5e6fb
add datetime overflow tests
galipremsagar Sep 23, 2022
b5ea2cc
cleanup
galipremsagar Sep 23, 2022
67c416b
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 23, 2022
5c3ac19
rename
galipremsagar Sep 23, 2022
81d5e51
Merge branch 'rapidsai:branch-22.10' into 11155
galipremsagar Sep 23, 2022
014c141
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 26, 2022
5ec1079
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 26, 2022
d690063
add cpp tests
galipremsagar Sep 27, 2022
ee4997a
Merge branch '11155' of https://github.com/galipremsagar/cudf into 11155
galipremsagar Sep 27, 2022
9c30dd7
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 27, 2022
8d66fc0
fix test
galipremsagar Sep 27, 2022
cc3e486
Merge branch 'rapidsai:branch-22.10' into 11155
galipremsagar Sep 27, 2022
12c8f1b
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 27, 2022
da26425
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 27, 2022
6d556e1
move logic to as_string_column
galipremsagar Sep 27, 2022
9c5a2df
todo
galipremsagar Sep 27, 2022
b48155e
Update cpp/src/datetime/datetime_ops.cu
galipremsagar Sep 27, 2022
09a9986
Update cpp/src/datetime/datetime_ops.cu
galipremsagar Sep 27, 2022
0438b71
rename API name
galipremsagar Sep 27, 2022
76d4234
Update cpp/include/cudf/datetime.hpp
galipremsagar Sep 27, 2022
b0750ca
add examples
galipremsagar Sep 27, 2022
55c5ab9
add comments
galipremsagar Sep 27, 2022
c8e78ca
remove redundant code and docstrings
galipremsagar Sep 27, 2022
d31060a
document categorical index conversion with example
galipremsagar Sep 27, 2022
735de4b
Merge remote-tracking branch 'upstream/branch-22.10' into 11155
galipremsagar Sep 27, 2022
872a1b7
Update python/cudf/cudf/core/index.py
galipremsagar Sep 27, 2022
1337b94
style
galipremsagar Sep 27, 2022
e2f9af7
merge
galipremsagar Oct 12, 2022
486bf42
revert all repr changes
galipremsagar Oct 12, 2022
1bf8893
Update cpp/include/cudf/datetime.hpp
galipremsagar Oct 12, 2022
0d61b99
Merge remote-tracking branch 'upstream/branch-22.12' into 11155_1
galipremsagar Oct 12, 2022
e3a1815
Apply suggestions from code review
galipremsagar Oct 12, 2022
1d61846
Update python/cudf/cudf/core/series.py
galipremsagar Oct 12, 2022
b79912b
Update python/cudf/cudf/core/series.py
galipremsagar Oct 12, 2022
38b1bd1
Update python/cudf/cudf/core/series.py
galipremsagar Oct 12, 2022
88d118a
fix inconsistencies
galipremsagar Oct 12, 2022
574fa80
Merge branch '11155_1' of https://github.com/galipremsagar/cudf into …
galipremsagar Oct 12, 2022
16e7b8f
reduce inefficiency
galipremsagar Oct 12, 2022
e78b806
add comment
galipremsagar Oct 12, 2022
cc94b09
Revert "reduce inefficiency"
galipremsagar Oct 12, 2022
1b8af1c
use const
galipremsagar Oct 12, 2022
9c8dbfb
use lambdas
galipremsagar Oct 12, 2022
7c7cdfc
remove ;s
galipremsagar Oct 12, 2022
2c9de71
remove ;s
galipremsagar Oct 12, 2022
90f1fee
Update python/cudf/cudf/core/series.py
galipremsagar Oct 13, 2022
206cdc0
Update python/cudf/cudf/core/series.py
galipremsagar Oct 13, 2022
82c51cf
Update python/cudf/cudf/core/series.py
galipremsagar Oct 13, 2022
5a0879c
remove duplication in test data and expand the test coverage
galipremsagar Oct 13, 2022
62cfcc8
reorder
galipremsagar Oct 13, 2022
c0c7aff
reorder
galipremsagar Oct 13, 2022
16ceb49
Merge remote-tracking branch 'upstream/branch-22.12' into 11155_1
galipremsagar Oct 14, 2022
c698435
address reviews
galipremsagar Oct 14, 2022
c3dc34c
cleanup millisecond
galipremsagar Oct 14, 2022
a67123b
Update docs/cudf/source/api_docs/series.rst
galipremsagar Oct 14, 2022
9c8b663
Update docs/cudf/source/api_docs/index_objects.rst
galipremsagar Oct 14, 2022
d32f61c
Merge remote-tracking branch 'upstream/branch-22.12' into 11155_1
galipremsagar Oct 17, 2022
cb1042c
fix docstring
galipremsagar Oct 17, 2022
a320c45
fix docstring
galipremsagar Oct 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 61 additions & 10 deletions cpp/include/cudf/datetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace datetime {
*/

/**
* @brief Extracts year from any date time type and returns an int16_t
* @brief Extracts year from any datetime type and returns an int16_t
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand All @@ -50,7 +50,7 @@ std::unique_ptr<cudf::column> extract_year(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts month from any date time type and returns an int16_t
* @brief Extracts month from any datetime type and returns an int16_t
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand All @@ -64,7 +64,7 @@ std::unique_ptr<cudf::column> extract_month(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts day from any date time type and returns an int16_t
* @brief Extracts day from any datetime type and returns an int16_t
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand All @@ -78,7 +78,7 @@ std::unique_ptr<cudf::column> extract_day(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts day from any date time type and returns an int16_t
* @brief Extracts day from any datetime type and returns an int16_t
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand All @@ -92,7 +92,7 @@ std::unique_ptr<cudf::column> extract_weekday(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts hour from any date time type and returns an int16_t
* @brief Extracts hour from any datetime type and returns an int16_t
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand All @@ -106,7 +106,7 @@ std::unique_ptr<cudf::column> extract_hour(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts minute from any date time type and returns an int16_t
* @brief Extracts minute from any datetime type and returns an int16_t
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand All @@ -120,7 +120,7 @@ std::unique_ptr<cudf::column> extract_minute(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts second from any date time type and returns an int16_t
* @brief Extracts second from any datetime type and returns an int16_t
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand All @@ -133,6 +133,57 @@ std::unique_ptr<cudf::column> extract_second(
cudf::column_view const& column,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts millisecond fraction from any datetime type and returns an int16_t
* cudf::column.
*
* A millisecond fraction is only the 3 digits that make up the millisecond portion of a duration.
* For example, the millisecond fraction of 1.234567890 seconds is 234.
*
* @param column cudf::column_view of the input datetime values
* @param mr Device memory resource used to allocate device memory of the returned column
*
* @returns cudf::column of the extracted int16_t milliseconds
* @throw cudf::logic_error if input column datatype is not TIMESTAMP
*/
std::unique_ptr<cudf::column> extract_millisecond_fraction(
cudf::column_view const& column,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts microsecond fraction from any datetime type and returns an int16_t
* cudf::column.
*
* A microsecond fraction is only the 3 digits that make up the microsecond portion of a duration.
* For example, the microsecond fraction of 1.234567890 seconds is 567.
*
* @param column cudf::column_view of the input datetime values
* @param mr Device memory resource used to allocate device memory of the returned column
*
* @returns cudf::column of the extracted int16_t microseconds
* @throw cudf::logic_error if input column datatype is not TIMESTAMP
*/
std::unique_ptr<cudf::column> extract_microsecond_fraction(
cudf::column_view const& column,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Extracts nanosecond fraction from any datetime type and returns an int16_t
* cudf::column.
*
* A nanosecond fraction is only the 3 digits that make up the nanosecond portion of a duration.
* For example, the nanosecond fraction of 1.234567890 seconds is 890.
*
* @param column cudf::column_view of the input datetime values
* @param mr Device memory resource used to allocate device memory of the returned column
*
* @returns cudf::column of the extracted int16_t nanoseconds
* @throw cudf::logic_error if input column datatype is not TIMESTAMP
*/
std::unique_ptr<cudf::column> extract_nanosecond_fraction(
cudf::column_view const& column,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/** @} */ // end of group
/**
* @addtogroup datetime_compute
Expand All @@ -141,7 +192,7 @@ std::unique_ptr<cudf::column> extract_second(
*/

/**
* @brief Computes the last day of the month in date time type and returns a TIMESTAMP_DAYS
* @brief Computes the last day of the month in datetime type and returns a TIMESTAMP_DAYS
* cudf::column.
*
* @param column cudf::column_view of the input datetime values
Expand Down Expand Up @@ -169,7 +220,7 @@ std::unique_ptr<cudf::column> day_of_year(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Adds or subtracts a number of months from the date time type and returns a
* @brief Adds or subtracts a number of months from the datetime type and returns a
* timestamp column that is of the same type as the input `timestamps` column.
*
* For a given row, if the `timestamps` or the `months` column value is null,
Expand Down Expand Up @@ -204,7 +255,7 @@ std::unique_ptr<cudf::column> add_calendrical_months(
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Adds or subtracts a number of months from the date time type and returns a
* @brief Adds or subtracts a number of months from the datetime type and returns a
* timestamp column that is of the same type as the input `timestamps` column.
*
* For a given row, if the `timestamps` value is null, the output for that row is null.
Expand Down
33 changes: 33 additions & 0 deletions cpp/include/cudf/detail/datetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,39 @@ std::unique_ptr<cudf::column> extract_second(
rmm::cuda_stream_view stream = cudf::default_stream_value,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @copydoc cudf::extract_millisecond_fraction(cudf::column_view const&,
* rmm::mr::device_memory_resource *)
*
* @param stream CUDA stream used for device memory operations and kernel launches.
*/
std::unique_ptr<cudf::column> extract_millisecond_fraction(
cudf::column_view const& column,
rmm::cuda_stream_view stream = cudf::default_stream_value,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @copydoc cudf::extract_microsecond_fraction(cudf::column_view const&,
* rmm::mr::device_memory_resource *)
*
* @param stream CUDA stream used for device memory operations and kernel launches.
*/
std::unique_ptr<cudf::column> extract_microsecond_fraction(
cudf::column_view const& column,
rmm::cuda_stream_view stream = cudf::default_stream_value,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @copydoc cudf::extract_nanosecond_fraction(cudf::column_view const&,
* rmm::mr::device_memory_resource *)
*
* @param stream CUDA stream used for device memory operations and kernel launches.
*/
std::unique_ptr<cudf::column> extract_nanosecond_fraction(
cudf::column_view const& column,
rmm::cuda_stream_view stream = cudf::default_stream_value,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @copydoc cudf::last_day_of_month(cudf::column_view const&, rmm::mr::device_memory_resource *)
*
Expand Down
76 changes: 70 additions & 6 deletions cpp/src/datetime/datetime_ops.cu
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,22 @@ struct extract_component_operator {

if (time_since_midnight.count() < 0) { time_since_midnight += days(1); }

auto hrs_ = duration_cast<hours>(time_since_midnight);
auto mins_ = duration_cast<minutes>(time_since_midnight - hrs_);
auto secs_ = duration_cast<seconds>(time_since_midnight - hrs_ - mins_);
auto const hrs_ = [&] { return duration_cast<hours>(time_since_midnight); };
auto const mins_ = [&] { return duration_cast<minutes>(time_since_midnight) - hrs_(); };
auto const secs_ = [&] {
return duration_cast<seconds>(time_since_midnight) - hrs_() - mins_();
};
auto const millisecs_ = [&] {
return duration_cast<milliseconds>(time_since_midnight) - hrs_() - mins_() - secs_();
};
auto const microsecs_ = [&] {
return duration_cast<microseconds>(time_since_midnight) - hrs_() - mins_() - secs_() -
millisecs_();
};
auto const nanosecs_ = [&] {
return duration_cast<nanoseconds>(time_since_midnight) - hrs_() - mins_() - secs_() -
millisecs_() - microsecs_();
};

switch (Component) {
case datetime_component::YEAR:
Expand All @@ -89,9 +102,12 @@ struct extract_component_operator {
return static_cast<unsigned>(year_month_day(days_since_epoch).day());
case datetime_component::WEEKDAY:
return year_month_weekday(days_since_epoch).weekday().iso_encoding();
case datetime_component::HOUR: return hrs_.count();
case datetime_component::MINUTE: return mins_.count();
case datetime_component::SECOND: return secs_.count();
case datetime_component::HOUR: return hrs_().count();
case datetime_component::MINUTE: return mins_().count();
case datetime_component::SECOND: return secs_().count();
case datetime_component::MILLISECOND: return millisecs_().count();
case datetime_component::MICROSECOND: return microsecs_().count();
case datetime_component::NANOSECOND: return nanosecs_().count();
default: return 0;
}
}
Expand Down Expand Up @@ -495,6 +511,33 @@ std::unique_ptr<column> extract_second(column_view const& column,
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> extract_millisecond_fraction(column_view const& column,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
return detail::apply_datetime_op<
detail::extract_component_operator<detail::datetime_component::MILLISECOND>,
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> extract_microsecond_fraction(column_view const& column,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
return detail::apply_datetime_op<
detail::extract_component_operator<detail::datetime_component::MICROSECOND>,
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> extract_nanosecond_fraction(column_view const& column,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
return detail::apply_datetime_op<
detail::extract_component_operator<detail::datetime_component::NANOSECOND>,
cudf::type_id::INT16>(column, stream, mr);
}

std::unique_ptr<column> last_day_of_month(column_view const& column,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
Expand Down Expand Up @@ -607,6 +650,27 @@ std::unique_ptr<column> extract_second(column_view const& column,
return detail::extract_second(column, cudf::default_stream_value, mr);
}

std::unique_ptr<column> extract_millisecond_fraction(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_millisecond_fraction(column, cudf::default_stream_value, mr);
}

std::unique_ptr<column> extract_microsecond_fraction(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_microsecond_fraction(column, cudf::default_stream_value, mr);
}

std::unique_ptr<column> extract_nanosecond_fraction(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
return detail::extract_nanosecond_fraction(column, cudf::default_stream_value, mr);
}

std::unique_ptr<column> last_day_of_month(column_view const& column,
rmm::mr::device_memory_resource* mr)
{
Expand Down
Loading