lidavidm commented on code in PR #13412:
URL: https://github.com/apache/arrow/pull/13412#discussion_r941317519


##########
cpp/src/arrow/compute/api_vector.h:
##########
@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public 
FunctionOptions {
   bool check_overflow = false;
 };
 
+/// \brief Options for cumulative product function
+class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
+ public:
+  explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
+                                    bool check_overflow = false);
+  explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
+                                    bool skip_nulls = false, bool 
check_overflow = false);
+  static constexpr char const kTypeName[] = "CumulativeProductOptions";
+  static CumulativeProductOptions Defaults() { return 
CumulativeProductOptions(); }
+
+  const bool is_minmax = false;
+  const bool is_max = false;
+
+  /// Optional starting value for cumulative product
+  std::shared_ptr<Scalar> start;
+
+  /// If true, nulls in the input are ignored and produce a corresponding null 
output.
+  /// When false, the first null encountered is propagated through the 
remaining output.
+  bool skip_nulls = false;
+
+  /// When true, returns an Invalid Status when overflow is detected
+  bool check_overflow = false;
+};
+
+/// \brief Options for cumulative min functions
+class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
+ public:
+  explicit CumulativeMinOptions(bool skip_nulls = false);
+  explicit CumulativeMinOptions(double start, bool skip_nulls = false);
+  explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls 
= false);
+  static constexpr char const kTypeName[] = "CumulativeMinOptions";
+  static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }
+
+  const bool is_minmax = true;

Review Comment:
   nit: it might be more idiomatic to have this as `constexpr static bool`, 
then below use `if (OptionsType::is_minmax)`



##########
python/pyarrow/tests/test_compute.py:
##########
@@ -2605,6 +2608,204 @@ def test_cumulative_sum(start, skip_nulls):
             pc.cumulative_sum([1, 2, 3], start=strt)
 
 
[email protected]('start', (1.25, 10.5, -10.5))
[email protected]('skip_nulls', (True, False))
+def test_cumulative_product(start, skip_nulls):
+    # Exact tests (e.g., integral types)
+    start_int = int(start)
+    starts = [start_int, pa.scalar(start_int, type=pa.int8()),
+              pa.scalar(start_int, type=pa.int64())]
+    for strt in starts:
+        arrays = [
+            pa.array([1, 2, 3]),
+            pa.array([1, None, 3, 4]),
+            pa.chunked_array([[1, None], [3, 4]])
+        ]
+        expected_arrays = [
+            pa.array([1, 2, 6]),
+            pa.array([1, None, 3, 12])
+            if skip_nulls else pa.array([1, None, None, None]),
+            pa.chunked_array([[1, None, 3, 12]])
+            if skip_nulls else pa.chunked_array([[1, None, None, None]])
+        ]
+        for i, arr in enumerate(arrays):
+            result = pc.cumulative_product(
+                arr, start=strt, skip_nulls=skip_nulls)
+            # Add `start` offset to expected array before comparing
+            expected = pc.multiply(expected_arrays[i], strt)
+            assert result.equals(expected)
+
+    starts = [start, pa.scalar(start, type=pa.float32()),
+              pa.scalar(start, type=pa.float64())]
+    for strt in starts:
+        arrays = [
+            pa.array([1.125, 2.25, 3.03125]),
+            pa.array([1, np.nan, 2, -3, 4, 5]),
+            pa.array([1, np.nan, None, 3, None, 5])
+        ]
+        expected_arrays = [
+            np.array([1.125, 2.53125, 7.6728515625]),
+            np.array([1, np.nan, np.nan, np.nan, np.nan, np.nan]),
+            np.array([1, np.nan, None, np.nan, None, np.nan])
+            if skip_nulls else np.array([1, np.nan, None, None, None, None])
+        ]
+        for i, arr in enumerate(arrays):
+            result = pc.cumulative_product(
+                arr, start=strt, skip_nulls=skip_nulls)
+            # Add `start` offset to expected array before comparing
+            expected = pc.multiply(expected_arrays[i], strt)
+            np.testing.assert_array_almost_equal(result.to_numpy(

Review Comment:
   Are we converting to NumPy here because Arrow doesn't have an approx equals?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to