[
https://issues.apache.org/jira/browse/ARROW-12911?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17354737#comment-17354737
]
Yibo Cai commented on ARROW-12911:
----------------------------------
We have a {{min_count}} option to control whether to return null or 0.
There's a bug in current python code which makes this option not available to
pa.compute.sum. Will fix it soon.
For a quick test, you can delete below code and try again with option
{{min_count=0}}
https://github.com/apache/arrow/blob/master/python/pyarrow/compute.py#L370-L382
{code:python}
In [8]: pa.compute.sum(pa.array([], pa.int64()), min_count=0)
Out[8]: <pyarrow.Int64Scalar: 0>
{code}
> sum of zero rows gives null; should give 0
> ------------------------------------------
>
> Key: ARROW-12911
> URL: https://issues.apache.org/jira/browse/ARROW-12911
> Project: Apache Arrow
> Issue Type: Bug
> Components: C++, Python
> Affects Versions: 4.0.1
> Reporter: Adam Hooper
> Priority: Minor
>
> {code}
> >>> pa.compute.sum(pa.array([], pa.int64()))
> <pyarrow.Int64Scalar: None>
> {code}
> I'd expect 0.
> I can't think of any reason for NULL, except that SQL returns NULL. But I
> can't figure out why SQL returns NULL. Does anybody know? Any textbook -- and
> https://en.wikipedia.org/wiki/Summation -- specifies 0.
> Pandas and Numpy return 0. Also, Apache Arrow c_glib implementation returns 0
> -- and even tests for it:
> https://github.com/apache/arrow/blob/master/c_glib/test/test-int8-array.rb#L60
> Workaround is to replace all NULLs with 0 after running the computation.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)