Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-14101: [C++] multiply(duration, integer) -> duration kernel#12215
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1455,6 +1455,50 @@ TEST_F(ScalarTemporalTest, TestTemporalSubtractDuration) { | ||
| } | ||
| } | ||
| TEST_F(ScalarTemporalTest, TestTemporalMultiplyDuration) { | ||
| std::shared_ptr<Array> max_array; | ||
| auto max = std::numeric_limits<int64_t>::max(); | ||
| ArrayFromVector<Int64Type, int64_t>({max, max, max, max, max}, &max_array); | ||
| for (auto u : TimeUnit::values()) { | ||
| auto unit = duration(u); | ||
| auto durations = ArrayFromJSON(unit, R"([0, -1, 2, 6, null])"); | ||
| auto multipliers = ArrayFromJSON(int64(), R"([0, 3, 2, 7, null])"); | ||
| auto durations_multiplied = ArrayFromJSON(unit, R"([0, -3, 4, 42, null])"); | ||
| CheckScalarBinary("multiply", durations, multipliers, durations_multiplied); | ||
| CheckScalarBinary("multiply", multipliers, durations, durations_multiplied); | ||
| CheckScalarBinary("multiply_checked", durations, multipliers, durations_multiplied); | ||
| CheckScalarBinary("multiply_checked", multipliers, durations, durations_multiplied); | ||
| EXPECT_RAISES_WITH_MESSAGE_THAT( | ||
| Invalid, ::testing::HasSubstr("Invalid: overflow"), | ||
| CallFunction("multiply_checked", {durations, max_array})); | ||
| EXPECT_RAISES_WITH_MESSAGE_THAT( | ||
| Invalid, ::testing::HasSubstr("Invalid: overflow"), | ||
| CallFunction("multiply_checked", {max_array, durations})); | ||
| } | ||
| } | ||
| TEST_F(ScalarTemporalTest, TestTemporalDivideDuration) { | ||
| for (auto u : TimeUnit::values()) { | ||
| auto unit = duration(u); | ||
| auto divided_durations = ArrayFromJSON(unit, R"([0, -1, -2, 6, null])"); | ||
| auto divisors = ArrayFromJSON(int64(), R"([3, 3, -2, 7, null])"); | ||
| auto durations = ArrayFromJSON(unit, R"([1, -3, 4, 42, null])"); | ||
| auto zeros = ArrayFromJSON(int64(), R"([0, 0, 0, 0, null])"); | ||
| CheckScalarBinary("divide", durations, divisors, divided_durations); | ||
| CheckScalarBinary("divide_checked", durations, divisors, divided_durations); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also check that division by zero raises? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. | ||
| EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, | ||
| ::testing::HasSubstr("Invalid: divide by zero"), | ||
| CallFunction("divide", {durations, zeros})); | ||
| EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, | ||
| ::testing::HasSubstr("Invalid: divide by zero"), | ||
| CallFunction("divide_checked", {durations, zeros})); | ||
| } | ||
| } | ||
| TEST_F(ScalarTemporalTest, TestTemporalDifferenceWeeks) { | ||
| auto raw_days = ArrayFromJSON(timestamp(TimeUnit::SECOND), R"([ | ||
| "2021-08-09", "2021-08-10", "2021-08-11", "2021-08-12", "2021-08-13", "2021-08-14", "2021-08-15", | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -441,13 +441,13 @@ Mixed time resolution temporal inputs will be cast to finest input resolution. | ||
| +------------------+--------+------------------+----------------------+-------+ | ||
| | add_checked | Binary | Numeric/Temporal | Numeric/Temporal | \(1) | | ||
| +------------------+--------+------------------+----------------------+-------+ | ||
| | divide | Binary | Numeric| Numeric | \(1) | | ||
| | divide | Binary | Numeric/Temporal | Numeric/Temporal | \(1) | | ||
| +------------------+--------+------------------+----------------------+-------+ | ||
| | divide_checked | Binary | Numeric| Numeric | \(1) | | ||
| | divide_checked | Binary | Numeric/Temporal | Numeric/Temporal | \(1) | | ||
| +------------------+--------+------------------+----------------------+-------+ | ||
| | multiply | Binary | Numeric| Numeric | \(1) | | ||
| | multiply | Binary | Numeric/Temporal | Numeric/Temporal | \(1) | | ||
rok marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| +------------------+--------+------------------+----------------------+-------+ | ||
| | multiply_checked | Binary | Numeric| Numeric | \(1) | | ||
| | multiply_checked | Binary | Numeric/Temporal | Numeric/Temporal | \(1) | | ||
| +------------------+--------+------------------+----------------------+-------+ | ||
| | negate | Unary | Numeric | Numeric | | | ||
| +------------------+--------+------------------+----------------------+-------+ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unexpected to me since
int64is not a temporal at all. @lidavidm What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, but maybe we need a better name for what this function does.
That said, I don't think this change is needed for this function to work, anyways. There's only a single temporal argument so there isn't really a meaningful common resolution to cast to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, the function doesn't seem to have changed :-). It's just the additional test that surprised me (but adding a test for existing behaviour is useful, thank you @rok ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well duration has a unit and int64 is dimensionless. The goal of the function is to find the best common unit and I'd argue it still does.