Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit a16a683

Browse files
authored
correct doc for DF.sum (#693)
1 parent 5464b10 commit a16a683

File tree

2 files changed

+106
-22
lines changed

2 files changed

+106
-22
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
A 1.0
30+
B 10.0
31+
C inf
32+
dtype: float64
33+
"""
34+
35+
import pandas as pd
36+
import numpy as np
37+
from numba import njit
38+
39+
40+
@njit
41+
def dataframe_sum():
42+
df = pd.DataFrame({"A": [.2, .0, .6, .2],
43+
"B": [2, 0, 6, 2],
44+
"C": [-1, np.nan, 1, np.inf]})
45+
46+
return df.sum()
47+
48+
49+
print(dataframe_sum())

sdc/datatypes/hpat_pandas_dataframe_functions.py

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -947,32 +947,67 @@ def min_overload(df, axis=None, skipna=None, level=None, numeric_only=None):
947947
@sdc_overload_method(DataFrameType, 'sum')
948948
def sum_overload(df, axis=None, skipna=None, level=None, numeric_only=None, min_count=0):
949949
"""
950-
Pandas DataFrame method :meth:`pandas.DataFrame.sum` implementation.
950+
Intel Scalable Dataframe Compiler User Guide
951+
********************************************
951952
952-
.. only:: developer
953+
Pandas API: pandas.DataFrame.sum
953954
954-
Test: python -m sdc.runtests -k sdc.tests.test_dataframe.TestDataFrame.test_sum*
955+
Limitations
956+
-----------
957+
Parameters ``axis``, ``level``, ``numeric_only`` and ``min_count`` are unsupported.
955958
956-
Parameters
957-
-----------
958-
df: :class:`pandas.DataFrame`
959-
input arg
960-
axis:
961-
*unsupported*
962-
skipna:
963-
*unsupported*
964-
level:
965-
*unsupported*
966-
numeric_only:
967-
*unsupported*
968-
min_count:
969-
*unsupported*
959+
Examples
960+
--------
961+
.. literalinclude:: ../../../examples/dataframe/dataframe_sum.py
962+
:language: python
963+
:lines: 35-
964+
:caption: Return the sum of the values for the columns.
965+
:name: ex_dataframe_sum
970966
971-
Returns
972-
-------
973-
:obj:`pandas.Series` or `pandas.DataFrame`
974-
return the sum of the values for the requested axis.
975-
"""
967+
.. command-output:: python ./dataframe/dataframe_sum.py
968+
:cwd: ../../../examples
969+
970+
.. seealso::
971+
972+
:ref:`Series.sum <pandas.Series.sum>`
973+
Return the sum.
974+
975+
:ref:`Series.min <pandas.Series.min>`
976+
Return the minimum.
977+
978+
:ref:`Series.max <pandas.Series.max>`
979+
Return the maximum.
980+
981+
:ref:`Series.idxmin <pandas.Series.idxmin>`
982+
Return the index of the minimum.
983+
984+
:ref:`Series.idxmax <pandas.Series.idxmax>`
985+
Return the index of the maximum.
986+
987+
:ref:`DataFrame.sum <pandas.DataFrame.sum>`
988+
Return the sum over the requested axis.
989+
990+
:ref:`DataFrame.min <pandas.DataFrame.min>`
991+
Return the minimum over the requested axis.
992+
993+
:ref:`DataFrame.max <pandas.DataFrame.max>`
994+
Return the maximum over the requested axis.
995+
996+
:ref:`DataFrame.idxmin <pandas.DataFrame.idxmin>`
997+
Return the index of the minimum over the requested axis.
998+
999+
:ref:`DataFrame.idxmax <pandas.DataFrame.idxmax>`
1000+
Return the index of the maximum over the requested axis.
1001+
1002+
Intel Scalable Dataframe Compiler Developer Guide
1003+
*************************************************
1004+
1005+
Pandas DataFrame method :meth:`pandas.DataFrame.sum` implementation.
1006+
1007+
.. only:: developer
1008+
1009+
Test: python -m sdc.runtests -k sdc.tests.test_dataframe.TestDataFrame.test_sum*
1010+
"""
9761011

9771012
name = 'sum'
9781013

0 commit comments

Comments
 (0)