Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-36240: [Python] Refactor CumulativeSumOptions to a separate class for independent deprecation #36977

Merged
merged 21 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 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)
R-JunmingChen marked this conversation as resolved.
Show resolved Hide resolved


class CumulativeOptions(_CumulativeOptions):
Expand All @@ -1974,6 +1975,26 @@ 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,
)
R-JunmingChen marked this conversation as resolved.
Show resolved Hide resolved
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 if
# when the deprecated class CumulativeSumOptions is removed.
R-JunmingChen marked this conversation as resolved.
Show resolved Hide resolved
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