@@ -1685,7 +1685,10 @@ def _str_accumulate(
16851685 if name == "cumsum" :
16861686 pa_array = pc .fill_null (pa_array , "" )
16871687 else :
1688+ # After the first non-NA value we can retain the running min/max
1689+ # by forward filling.
16881690 pa_array = pc .fill_null_forward (pa_array )
1691+ # But any leading NA values should result in "".
16891692 nulls = pc .is_null (pa_array )
16901693 idx = pc .index (nulls , False ).as_py ()
16911694 if idx == - 1 :
@@ -1694,17 +1697,20 @@ def _str_accumulate(
16941697 head = pa .array (["" ] * idx , type = pa_array .type )
16951698 pa_array = pa_array [idx :].combine_chunks ()
16961699 else :
1700+ # When not skipping NA values, the result should be null from
1701+ # the first NA value onward.
16971702 nulls = pc .is_null (pa_array )
16981703 idx = pc .index (nulls , True ).as_py ()
16991704 tail = pa .nulls (len (pa_array ) - idx , type = pa_array .type )
17001705 pa_array = pa_array [:idx ].combine_chunks ()
17011706
17021707 pa_result = pa .array (np_func (pa_array ), type = pa_array .type )
17031708
1704- if head is not None or tail is not None :
1705- head = pa .array ([], type = pa_array .type ) if head is None else head
1706- tail = pa .array ([], type = pa_array .type ) if tail is None else tail
1707- pa_result = pa .concat_arrays ([head , pa_result , tail ])
1709+ assert head is None or tail is None
1710+ if head is not None :
1711+ pa_result = pa .concat_arrays ([head , pa_result ])
1712+ elif tail is not None :
1713+ pa_result = pa .concat_arrays ([pa_result , tail ])
17081714
17091715 result = type (self )(pa_result )
17101716 return result
0 commit comments