Skip to content

GH-48003: [C++][Compute] Multiply and divide durations by float64 - #55460

Open
JonSnow1807 wants to merge 4 commits into
apache:mainfrom
JonSnow1807:GH-48003-duration-float-multiply-min
Open

JonSnow1807 wants to merge 4 commits into
apache:mainfrom
JonSnow1807:GH-48003-duration-float-multiply-min

Conversation

@JonSnow1807

@JonSnow1807 JonSnow1807 commented Nov 9, 2026 •

Copy link
Copy Markdown

Rationale for this change

There is no kernel for multiply(duration, float64) or divide(duration, float64), so these calls raise NotImplemented (see #48003).

What changes are included in this PR?

Kernels for multiply(duration, float64), multiply(float64, duration) and divide(duration, float64), registered for multiply, multiply_checked, divide and divide_checked. The result keeps the duration’s unit and is truncated toward zero, like numpy and divide(duration, int64). NaN, overflow and division by zero return an error. Only float64 is handled; float32 and float16 are not cast.

Are these changes tested?

Yes, a new test in scalar_temporal_test.cc (truncation, both argument orders, nulls, errors, all four time units) and a small Python test with the example from the issue.

Are there any user-facing changes?

Yes, these calls now return a duration instead of raising NotImplemented.

Was AI used for this PR?

In accordance with the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Code drafted by both human and AI, and reviewed by human.

@JonSnow1807
JonSnow1807 requested a review from pitrou as a code owner November 9, 2026 22:18
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #48003 has been automatically assigned in GitHub to PR creator.

@rok

rok commented Nov 9, 2026

Copy link
Copy Markdown
Member

Please do adversarial review with your agents. Have them look at other kernels. Once you've done that please review this yourself such that you know what each line does, then ping me.

@rok

rok commented Nov 9, 2026

Copy link
Copy Markdown
Member

Also - add a small Python test that will use example proposed by Randolf in #48003.

@JonSnow1807

Copy link
Copy Markdown
Author

Thanks for the guidance. I ran an adversarial review with two separate reviewers and compared the kernel against the existing ones (round, checked arithmetic, casts, divide(duration, int64)). From that, the kernel now uses the physical Int64Type like its neighbours, the test also covers the lower int64 bound, and the docs say the computation is done in float64. I switched to truncation toward zero, so Randolf’s example now gives exactly numpy’s output, and I added it as a Python test. I’ve gone through every line myself. Also, to correct my earlier comment: float32 and float16 are not cast in this PR.

@rok

rok commented Nov 10, 2026

Copy link
Copy Markdown
Member

Thank you. I'll try to take a look tomorrow.
cc @randolf-scholz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants