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

Fix overflow for min calculation in strings::from_timestamps #9793

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions cpp/src/strings/convert/convert_datetime.cu
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ struct from_timestamp_base {
* scale( 61,60) -> 1
* @endcode
*/
__device__ int32_t scale_time(int64_t time, int64_t base) const
__device__ int64_t scale_time(int64_t time, int64_t base) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This most certainly would have been avoided if this code used chrono types directly instead of trying circumvent the types by using integers.

Filed #9812

{
return static_cast<int32_t>((time - ((time < 0) * (base - 1L))) / base);
return (time - ((time < 0) * (base - 1L))) / base;
};

__device__ time_components get_time_components(int64_t tstamp) const
Expand Down
8 changes: 5 additions & 3 deletions cpp/tests/strings/datetime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,23 @@ TEST_F(StringsDatetimeTest, FromTimestampAmPm)
TEST_F(StringsDatetimeTest, FromTimestampMillisecond)
{
cudf::test::fixed_width_column_wrapper<cudf::timestamp_ms, cudf::timestamp_ms::rep> timestamps_ms{
1530705600123, 1582934461007, 1451430122421, 1318302183999, -6106017600047};
1530705600123, 1582934461007, 1451430122421, 1318302183999, -6106017600047, 128849018880000};
auto results = cudf::strings::from_timestamps(timestamps_ms, "%Y-%m-%d %H:%M:%S.%3f");
cudf::test::strings_column_wrapper expected_ms{"2018-07-04 12:00:00.123",
"2020-02-29 00:01:01.007",
"2015-12-29 23:02:02.421",
"2011-10-11 03:03:03.999",
"1776-07-04 11:59:59.953"};
"1776-07-04 11:59:59.953",
"6053-01-23 02:08:00.000"};
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected_ms);

results = cudf::strings::from_timestamps(timestamps_ms, "%Y-%m-%d %H:%M:%S.%f");
cudf::test::strings_column_wrapper expected_ms_6f{"2018-07-04 12:00:00.123000",
"2020-02-29 00:01:01.007000",
"2015-12-29 23:02:02.421000",
"2011-10-11 03:03:03.999000",
"1776-07-04 11:59:59.953000"};
"1776-07-04 11:59:59.953000",
"6053-01-23 02:08:00.000000"};
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected_ms_6f);

cudf::test::fixed_width_column_wrapper<cudf::timestamp_ns, cudf::timestamp_ns::rep> timestamps_ns{
Expand Down