@@ -1685,7 +1685,10 @@ def _str_accumulate(
1685
1685
if name == "cumsum" :
1686
1686
pa_array = pc .fill_null (pa_array , "" )
1687
1687
else :
1688
+ # After the first non-NA value we can retain the running min/max
1689
+ # by forward filling.
1688
1690
pa_array = pc .fill_null_forward (pa_array )
1691
+ # But any leading NA values should result in "".
1689
1692
nulls = pc .is_null (pa_array )
1690
1693
idx = pc .index (nulls , False ).as_py ()
1691
1694
if idx == - 1 :
@@ -1694,17 +1697,20 @@ def _str_accumulate(
1694
1697
head = pa .array (["" ] * idx , type = pa_array .type )
1695
1698
pa_array = pa_array [idx :].combine_chunks ()
1696
1699
else :
1700
+ # When not skipping NA values, the result should be null from
1701
+ # the first NA value onward.
1697
1702
nulls = pc .is_null (pa_array )
1698
1703
idx = pc .index (nulls , True ).as_py ()
1699
1704
tail = pa .nulls (len (pa_array ) - idx , type = pa_array .type )
1700
1705
pa_array = pa_array [:idx ].combine_chunks ()
1701
1706
1702
1707
pa_result = pa .array (np_func (pa_array ), type = pa_array .type )
1703
1708
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 ])
1708
1714
1709
1715
result = type (self )(pa_result )
1710
1716
return result
0 commit comments