Skip to content

Commit

Permalink
GH-36240: [Python] Refactor CumulativeSumOptions to a separate class …
Browse files Browse the repository at this point in the history
…for independent deprecation (#36977)

**Rationale for this change**
As #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: #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]>
  • Loading branch information
3 people authored Aug 22, 2023
1 parent 369bb31 commit fe750ed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
26 changes: 24 additions & 2 deletions python/pyarrow/_compute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
CastOptions,
CountOptions,
CumulativeOptions,
CumulativeOptions as CumulativeSumOptions,
CumulativeSumOptions,
DayOfWeekOptions,
DictionaryEncodeOptions,
RunEndEncodeOptions,
Expand Down
7 changes: 6 additions & 1 deletion python/pyarrow/tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fe750ed

Please sign in to comment.