This is an automated email from the ASF dual-hosted git repository.

alenka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new fe750ed105 GH-36240: [Python] Refactor CumulativeSumOptions to a 
separate class for independent deprecation (#36977)
fe750ed105 is described below

commit fe750ed10531c47131b447397e67486656cf8135
Author: Junming Chen <[email protected]>
AuthorDate: Tue Aug 22 16:22:14 2023 +0800

    GH-36240: [Python] Refactor CumulativeSumOptions to a separate class for 
independent deprecation (#36977)
    
    **Rationale for this change**
    As https://github.com/apache/arrow/issues/36240 says, we refactor 
CumulativeSumOptions to a separate class.
    
    **What changes are included in this PR?**
    
    - independent CumulativeSumOptions
    - the original simple test before #32190
    - fix a typo in CumulativeOptions
    
    **Are these changes tested?**
    No.
    Actually, the PR can't pass the `test_option_class_equality` in 
test_compute.py ([Error 
example](https://github.com/apache/arrow/actions/runs/5728571658/job/15523443371?pr=36977)).
 Cause CumulativeSumOptions's C++ part is also CumulativeOptions.
    
![image](https://github.com/apache/arrow/assets/18380073/0a173684-47f8-4eb9-b8f4-ba72aa5aab97)
    
    **Are there any user-facing changes?**
    No.
    
    Closes: https://github.com/apache/arrow/issues/36240
    * Closes: #36240
    
    Lead-authored-by: Junming Chen <[email protected]>
    Co-authored-by: Dane Pitkin <[email protected]>
    Co-authored-by: Alenka Frim <[email protected]>
    Signed-off-by: AlenkaF <[email protected]>
---
 python/pyarrow/_compute.pyx          | 26 ++++++++++++++++++++++++--
 python/pyarrow/compute.py            |  2 +-
 python/pyarrow/tests/test_compute.py |  7 ++++++-
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx
index 453f487c4d..74b9c2ec8c 100644
--- a/python/pyarrow/_compute.pyx
+++ b/python/pyarrow/_compute.pyx
@@ -29,11 +29,12 @@ from pyarrow.lib cimport *
 from pyarrow.includes.common cimport *
 from pyarrow.includes.libarrow cimport *
 import pyarrow.lib as lib
-
+from pyarrow.util import _DEPR_MSG
 from libcpp cimport bool as c_bool
 
 import inspect
 import numpy as np
+import warnings
 
 
 def _forbid_instantiation(klass, subclasses_instead=True):
@@ -1947,7 +1948,7 @@ cdef class _CumulativeOptions(FunctionOptions):
                     pyarrow_unwrap_scalar(start), skip_nulls))
             except Exception:
                 _raise_invalid_function_option(
-                    start, "`start` type for CumulativeSumOptions", TypeError)
+                    start, "`start` type for CumulativeOptions", TypeError)
 
 
 class CumulativeOptions(_CumulativeOptions):
@@ -1974,6 +1975,27 @@ class CumulativeOptions(_CumulativeOptions):
         self._set_options(start, skip_nulls)
 
 
+class CumulativeSumOptions(_CumulativeOptions):
+    """
+    Options for `cumulative_sum` function.
+
+    Parameters
+    ----------
+    start : Scalar, default None
+        Starting value for sum computation
+    skip_nulls : bool, default False
+        When false, the first encountered null is propagated.
+    """
+
+    def __init__(self, start=None, *, skip_nulls=False):
+        warnings.warn(
+            _DEPR_MSG.format("CumulativeSumOptions", "14.0", 
"CumulativeOptions"),
+            FutureWarning,
+            stacklevel=2
+        )
+        self._set_options(start, skip_nulls)
+
+
 cdef class _PairwiseOptions(FunctionOptions):
     def _set_options(self, period):
         self.wrapped.reset(new CPairwiseOptions(period))
diff --git a/python/pyarrow/compute.py b/python/pyarrow/compute.py
index 7b8983cbb9..205ab393b8 100644
--- a/python/pyarrow/compute.py
+++ b/python/pyarrow/compute.py
@@ -34,7 +34,7 @@ from pyarrow._compute import (  # noqa
     CastOptions,
     CountOptions,
     CumulativeOptions,
-    CumulativeOptions as CumulativeSumOptions,
+    CumulativeSumOptions,
     DayOfWeekOptions,
     DictionaryEncodeOptions,
     RunEndEncodeOptions,
diff --git a/python/pyarrow/tests/test_compute.py 
b/python/pyarrow/tests/test_compute.py
index 30a3cdba36..6fbca52099 100644
--- a/python/pyarrow/tests/test_compute.py
+++ b/python/pyarrow/tests/test_compute.py
@@ -210,7 +210,12 @@ def test_option_class_equality():
         buf = option.serialize()
         deserialized = pc.FunctionOptions.deserialize(buf)
         assert option == deserialized
-        assert repr(option) == repr(deserialized)
+        # TODO remove the check under the if statement
+        # when the deprecated class CumulativeSumOptions is removed.
+        if repr(option).startswith("CumulativeSumOptions"):
+            assert repr(deserialized).startswith("CumulativeOptions")
+        else:
+            assert repr(option) == repr(deserialized)
     for option1, option2 in zip(options, options[1:]):
         assert option1 != option2
 

Reply via email to