You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/14 14:55:18 UTC

[GitHub] [arrow] edponce commented on a diff in pull request #12660: ARROW-15965: [C++][Python] Add Scalar constructor of RoundToMultipleOptions to Python

edponce commented on code in PR #12660:
URL: https://github.com/apache/arrow/pull/12660#discussion_r850529787


##########
cpp/src/arrow/compute/kernels/scalar_arithmetic.cc:
##########
@@ -1453,20 +1447,20 @@ struct RoundToMultiple<ArrowType, kRoundMode, enable_if_decimal<ArrowType>> {
   bool has_halfway_point;
 
   explicit RoundToMultiple(const State& state, const DataType& out_ty)
-      : ty(checked_cast<const ArrowType&>(out_ty)) {
-    const auto& options = state.options;
-    DCHECK(options.multiple);
-    DCHECK(options.multiple->is_valid);
-    DCHECK(options.multiple->type->Equals(out_ty));
-    multiple = UnboxScalar<ArrowType>::Unbox(*options.multiple);
-    half_multiple = multiple;
-    half_multiple /= 2;
-    neg_half_multiple = -half_multiple;
-    has_halfway_point = multiple.low_bits() % 2 == 0;
-  }
+      : ty(checked_cast<const ArrowType&>(out_ty)),
+        multiple(UnboxScalar<ArrowType>::Unbox(*state.options.multiple)),
+        half_multiple(multiple / 2),
+        neg_half_multiple(-half_multiple),
+        has_halfway_point(multiple.low_bits() % 2 == 0) {}
 
   template <typename T = ArrowType, typename CType = typename TypeTraits<T>::CType>
   enable_if_decimal_value<CType> Call(KernelContext* ctx, CType arg, Status* st) const {
+    // Return zeros if `multiple` option is zero.

Review Comment:
   Good catch. The general form of rounding to a multiple is `round(value / multiple) * multiple` which is not defined for `multiple = 0` (div-by-zero). Nevertheless, `mround` in Excel returns 0 when `multiple = 0`.
   Now, I think we should not support a `multiple = 0` and treat it as an error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org