You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Eduardo Ponce (Jira)" <ji...@apache.org> on 2022/04/02 00:49:00 UTC

[jira] [Comment Edited] (ARROW-13530) [C++] Implement cumulative sum compute function

    [ https://issues.apache.org/jira/browse/ARROW-13530?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17516180#comment-17516180 ] 

Eduardo Ponce edited comment on ARROW-13530 at 4/2/22 12:48 AM:
----------------------------------------------------------------

Different cumsum implementations have different behaviors wrt to nested inputs.
 # Which one should Arrow's cumsum follow?
 # Should a ChunkedArray input output a ChunkedArray of same shape or output a flattened Array?

 * *Pandas*
{code:python}
# Performs a "cumulative concatenate" operation for all nested lists
>>> d = pd.Series([[1,2],[3,4]])
>>> d.cumsum()
0          [1, 2]
1    [1, 2, 3, 4]
dtype: object

>>> d = pd.Series([[1,2,[3,4]],[[5,6],7],[8,9]])
>>> d.cumsum(axis=0)
0                     [1, 2, [3, 4]]
1          [1, 2, [3, 4], [5, 6], 7]
2    [1, 2, [3, 4], [5, 6], 7, 8, 9]
dtype: object
{code}

 * *Numpy*
{code:python}
#   Case 1: If all of the array elements have the same nested depth, then it flattens the array and applies cumsum.
>>> d = np.array([[1,2],[3,4]])
>>> d.cumsum()
array([ 1,  3,  6, 10])

#   Case 2: If array contains different nested depths, then cumsum represents a "cumulative concatenate" operation
>>> d = np.array([[1,2,[3,4]],[[5,6],7],[8,9]])
>>> d.cumsum()
array([list([1, 2, [3, 4]]), list([1, 2, [3, 4], [5, 6], 7]),
       list([1, 2, [3, 4], [5, 6], 7, 8, 9])], dtype=object)
{code}

 * *R*

 # 
{code:r}
# Flattens the nested list, then applies a cumsum
> cumsum(c(c(1,2),c(3,4)))
[1]  1  3  6 10

> cumsum(c(c(1,2,c(3,4)),c(c(5,6),7),c(8,9)))
[1]  1  3  6 10 15 21 28 36 45
{code}


was (Author: edponce):
Different cumsum implementations have different behaviors wrt to nested inputs. Which one should Arrow's cumsum follow?

* *Pandas*
{code:python}
# Performs a "cumulative concatenate" operation for all nested lists
>>> d = pd.Series([[1,2],[3,4]])
>>> d.cumsum()
0          [1, 2]
1    [1, 2, 3, 4]
dtype: object

>>> d = pd.Series([[1,2,[3,4]],[[5,6],7],[8,9]])
>>> d.cumsum(axis=0)
0                     [1, 2, [3, 4]]
1          [1, 2, [3, 4], [5, 6], 7]
2    [1, 2, [3, 4], [5, 6], 7, 8, 9]
dtype: object
{code}

* *Numpy*
{code:python}
#   Case 1: If all of the array elements have the same nested depth, then it flattens the array and applies cumsum.
>>> d = np.array([[1,2],[3,4]])
>>> d.cumsum()
array([ 1,  3,  6, 10])

#   Case 2: If array contains different nested depths, then cumsum represents a "cumulative concatenate" operation
>>> d = np.array([[1,2,[3,4]],[[5,6],7],[8,9]])
>>> d.cumsum()
array([list([1, 2, [3, 4]]), list([1, 2, [3, 4], [5, 6], 7]),
       list([1, 2, [3, 4], [5, 6], 7, 8, 9])], dtype=object)
{code}

* *R*
# {code:r}
# Flattens the nested list, then applies a cumsum
> cumsum(c(c(1,2),c(3,4)))
[1]  1  3  6 10

> cumsum(c(c(1,2,c(3,4)),c(c(5,6),7),c(8,9)))
[1]  1  3  6 10 15 21 28 36 45
{code}

> [C++] Implement cumulative sum compute function
> -----------------------------------------------
>
>                 Key: ARROW-13530
>                 URL: https://issues.apache.org/jira/browse/ARROW-13530
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>            Reporter: Antoine Pitrou
>            Assignee: Jabari Booker
>            Priority: Major
>              Labels: good-first-issue, good-second-issue, kernel, pull-request-available
>             Fix For: 8.0.0
>
>          Time Spent: 10h 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.1#820001)