JabariBooker commented on code in PR #12460:
URL: https://github.com/apache/arrow/pull/12460#discussion_r874166423
##########
python/pyarrow/tests/test_compute.py:
##########
@@ -2510,6 +2511,63 @@ def test_min_max_element_wise():
assert result == pa.array([1, 2, None])
[email protected]('start', (1.1, 10.5, -10.5))
[email protected]('skip_nulls', (True, False))
+def test_cumulative_sum(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([0, None, 20, 30]),
+ pa.chunked_array([[0, None], [20, 30]])
+ ]
+ expected_arrays = [
+ pa.array([1, 3, 6]),
+ pa.array([0, None, 20, 50])
+ if skip_nulls else pa.array([0, None, None, None]),
+ pa.chunked_array([[0, None, 20, 50]])
+ if skip_nulls else pa.chunked_array([[0, None, None, None]])
+ ]
+ for i, arr in enumerate(arrays):
+ result = pc.cumulative_sum(arr, start=strt, skip_nulls=skip_nulls)
+ # Add `start` offset to expected array before comparing
+ expected = pc.add(expected_arrays[i], strt)
+ assert result.equals(expected)
+
+ # Approximate and NaN tests (e.g., floating-point types)
+ # NOTE: Conversion from Arrow to NumPy replaces null slots with NaNs
+ # which prevent fully validating both states of `skip_nulls` for
+ # floating-point values. Ideally, equality comparisons make use of Arrow's
+ # `equals()` functions but an approximate version is not exposed in Python.
Review Comment:
Wouldn't this also have to be true for the `start` values as well?
--
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]