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 38 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
51 changes: 51 additions & 0 deletions cpp/include/cudf/datetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 date time type and returns an int16_t
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
* cudf::column.
*
* A millisecond fraction is only the 3 digits that make up the millisecond portion of a duration.
* For example, the microsecond fraction of 1.234567890 seconds is 234.
bdice marked this conversation as resolved.
Show resolved Hide resolved
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
*
* @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 date time 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 date time 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 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
62 changes: 59 additions & 3 deletions cpp/src/datetime/datetime_ops.cu
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ 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 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 millisecs_ = duration_cast<milliseconds>(time_since_midnight - hrs_ - mins_ - secs_);
auto microsecs_ =
duration_cast<microseconds>(time_since_midnight - hrs_ - mins_ - secs_ - millisecs_);
auto nanosecs_ = duration_cast<nanoseconds>(time_since_midnight - hrs_ - mins_ - secs_ -
millisecs_ - microsecs_);
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved

switch (Component) {
case datetime_component::YEAR:
Expand All @@ -92,6 +97,9 @@ struct extract_component_operator {
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 +503,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 +642,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
54 changes: 54 additions & 0 deletions cpp/tests/datetime/datetime_ops_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ TYPED_TEST(NonTimestampTest, TestThrowsOnNonTimestamp)
EXPECT_THROW(extract_hour(col), cudf::logic_error);
EXPECT_THROW(extract_minute(col), cudf::logic_error);
EXPECT_THROW(extract_second(col), cudf::logic_error);
EXPECT_THROW(extract_millisecond_fraction(col), cudf::logic_error);
EXPECT_THROW(extract_microsecond_fraction(col), cudf::logic_error);
EXPECT_THROW(extract_nanosecond_fraction(col), cudf::logic_error);
EXPECT_THROW(last_day_of_month(col), cudf::logic_error);
EXPECT_THROW(day_of_year(col), cudf::logic_error);
EXPECT_THROW(add_calendrical_months(
Expand Down Expand Up @@ -97,54 +100,102 @@ TEST_F(BasicDatetimeOpsTest, TestExtractingDatetimeComponents)
1674631932929 // 2023-01-25 07:32:12.929 GMT
};

auto timestamps_ns =
cudf::test::fixed_width_column_wrapper<cudf::timestamp_ns, cudf::timestamp_ns::rep>{
-23324234, // 1969-12-31 23:59:59.976675766 GMT
23432424, // 1970-01-01 00:00:00.023432424 GMT
987234623 // 1970-01-01 00:00:00.987234623 GMT
};

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_year(timestamps_D),
fixed_width_column_wrapper<int16_t>{1965, 2018, 2023});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_year(timestamps_s),
fixed_width_column_wrapper<int16_t>{1965, 2018, 2023});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_year(timestamps_ms),
fixed_width_column_wrapper<int16_t>{1965, 2018, 2023});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_year(timestamps_ns),
fixed_width_column_wrapper<int16_t>{1969, 1970, 1970});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_month(timestamps_D),
fixed_width_column_wrapper<int16_t>{10, 7, 1});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_month(timestamps_s),
fixed_width_column_wrapper<int16_t>{10, 7, 1});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_month(timestamps_ms),
fixed_width_column_wrapper<int16_t>{10, 7, 1});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_month(timestamps_ns),
fixed_width_column_wrapper<int16_t>{12, 1, 1});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_day(timestamps_D),
fixed_width_column_wrapper<int16_t>{26, 4, 25});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_day(timestamps_s),
fixed_width_column_wrapper<int16_t>{26, 4, 25});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_day(timestamps_ms),
fixed_width_column_wrapper<int16_t>{26, 4, 25});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_day(timestamps_ns),
fixed_width_column_wrapper<int16_t>{31, 1, 1});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_weekday(timestamps_D),
fixed_width_column_wrapper<int16_t>{2, 3, 3});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_weekday(timestamps_s),
fixed_width_column_wrapper<int16_t>{2, 3, 3});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_weekday(timestamps_ms),
fixed_width_column_wrapper<int16_t>{2, 3, 3});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_weekday(timestamps_ms),
fixed_width_column_wrapper<int16_t>{2, 3, 3});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_hour(timestamps_D),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_hour(timestamps_s),
fixed_width_column_wrapper<int16_t>{14, 12, 7});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_hour(timestamps_ms),
fixed_width_column_wrapper<int16_t>{14, 12, 7});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_hour(timestamps_ns),
fixed_width_column_wrapper<int16_t>{23, 0, 0});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_minute(timestamps_D),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_minute(timestamps_s),
fixed_width_column_wrapper<int16_t>{1, 0, 32});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_minute(timestamps_ms),
fixed_width_column_wrapper<int16_t>{1, 0, 32});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_minute(timestamps_ns),
fixed_width_column_wrapper<int16_t>{59, 0, 0});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_second(timestamps_D),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_second(timestamps_s),
fixed_width_column_wrapper<int16_t>{12, 0, 12});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_second(timestamps_ms),
fixed_width_column_wrapper<int16_t>{12, 0, 12});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_minute(timestamps_ns),
fixed_width_column_wrapper<int16_t>{59, 0, 0});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_millisecond_fraction(timestamps_D),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_millisecond_fraction(timestamps_s),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_millisecond_fraction(timestamps_ms),
fixed_width_column_wrapper<int16_t>{762, 0, 929});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_millisecond_fraction(timestamps_ns),
fixed_width_column_wrapper<int16_t>{976, 23, 987});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_microsecond_fraction(timestamps_D),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_microsecond_fraction(timestamps_s),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_microsecond_fraction(timestamps_ms),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_microsecond_fraction(timestamps_ns),
fixed_width_column_wrapper<int16_t>{675, 432, 234});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_nanosecond_fraction(timestamps_D),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_nanosecond_fraction(timestamps_s),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_nanosecond_fraction(timestamps_ms),
fixed_width_column_wrapper<int16_t>{0, 0, 0});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_nanosecond_fraction(timestamps_ns),
fixed_width_column_wrapper<int16_t>{766, 424, 623});
}

template <typename T>
Expand Down Expand Up @@ -175,6 +226,9 @@ TYPED_TEST(TypedDatetimeOpsTest, TestEmptyColumns)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_hour(timestamps), int16s);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_minute(timestamps), int16s);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_second(timestamps), int16s);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_millisecond_fraction(timestamps), int16s);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_microsecond_fraction(timestamps), int16s);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*extract_nanosecond_fraction(timestamps), int16s);
}

TYPED_TEST(TypedDatetimeOpsTest, TestExtractingGeneratedDatetimeComponents)
Expand Down
3 changes: 3 additions & 0 deletions docs/cudf/source/api_docs/index_objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ Time/date components
DatetimeIndex.hour
DatetimeIndex.minute
DatetimeIndex.second
DatetimeIndex.millisecond
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
DatetimeIndex.microsecond
DatetimeIndex.nanosecond
DatetimeIndex.dayofweek
DatetimeIndex.dayofyear
DatetimeIndex.day_of_year
Expand Down
3 changes: 3 additions & 0 deletions docs/cudf/source/api_docs/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,11 @@ Datetime properties
days_in_month
day_of_year
hour
microsecond
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
millisecond
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
minute
month
nanosecond
second
weekday
year
Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf/_lib/cpp/datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ cdef extern from "cudf/datetime.hpp" namespace "cudf::datetime" nogil:
cdef unique_ptr[column] extract_hour(const column_view& column) except +
cdef unique_ptr[column] extract_minute(const column_view& column) except +
cdef unique_ptr[column] extract_second(const column_view& column) except +
cdef unique_ptr[column] extract_millisecond_fraction(
const column_view& column
) except +
cdef unique_ptr[column] extract_microsecond_fraction(
const column_view& column
) except +
cdef unique_ptr[column] extract_nanosecond_fraction(
const column_view& column
) except +

ctypedef enum rounding_frequency "cudf::datetime::rounding_frequency":
DAY "cudf::datetime::rounding_frequency::DAY"
Expand Down
12 changes: 12 additions & 0 deletions python/cudf/cudf/_lib/datetime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ def extract_datetime_component(Column col, object field):
c_result = move(libcudf_datetime.extract_minute(col_view))
elif field == "second":
c_result = move(libcudf_datetime.extract_second(col_view))
elif field == "milli_second":
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
c_result = move(
libcudf_datetime.extract_millisecond_fraction(col_view)
)
elif field == "micro_second":
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
c_result = move(
libcudf_datetime.extract_microsecond_fraction(col_view)
)
elif field == "nano_second":
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
c_result = move(
libcudf_datetime.extract_nanosecond_fraction(col_view)
)
elif field == "day_of_year":
c_result = move(libcudf_datetime.day_of_year(col_view))
else:
Expand Down
Loading