Skip to content

Commit 0acb69c

Browse files
DOC: add RT03 for pandas.DataFrame.sum
1 parent 02708ed commit 0acb69c

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7676
-i "pandas.DataFrame.min RT03" \
7777
-i "pandas.DataFrame.plot PR02,SA01" \
7878
-i "pandas.DataFrame.std PR01,RT03,SA01" \
79-
-i "pandas.DataFrame.sum RT03" \
8079
-i "pandas.DataFrame.swaplevel SA01" \
8180
-i "pandas.DataFrame.to_markdown SA01" \
8281
-i "pandas.DataFrame.var PR01,RT03,SA01" \

pandas/core/frame.py

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11709,7 +11709,6 @@ def max(
1170911709
return result
1171011710

1171111711
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="sum")
11712-
@doc(make_doc("sum", ndim=2))
1171311712
def sum(
1171411713
self,
1171511714
axis: Axis | None = 0,
@@ -11718,6 +11717,88 @@ def sum(
1171811717
min_count: int = 0,
1171911718
**kwargs,
1172011719
) -> Series:
11720+
"""
11721+
Return the sum of the values over the requested axis.
11722+
11723+
This is equivalent to the method ``numpy.sum``.
11724+
11725+
Parameters
11726+
----------
11727+
axis : {index (0), columns (1)}
11728+
Axis for the function to be applied on.
11729+
For `Series` this parameter is unused and defaults to 0.
11730+
11731+
.. warning::
11732+
11733+
The behavior of DataFrame.sum with ``axis=None`` is deprecated,
11734+
in a future version this will reduce over both axes and return a scalar
11735+
To retain the old behavior, pass axis=0 (or do not pass axis).
11736+
11737+
.. versionadded:: 2.0.0
11738+
11739+
skipna : bool, default True
11740+
Exclude NA/null values when computing the result.
11741+
numeric_only : bool, default False
11742+
Include only float, int, boolean columns. Not implemented for Series.
11743+
11744+
min_count : int, default 0
11745+
The required number of valid values to perform the operation. If fewer than
11746+
``min_count`` non-NA values are present the result will be NA.
11747+
**kwargs
11748+
Additional keyword arguments to be passed to the function.
11749+
11750+
Returns
11751+
-------
11752+
Series or scalar
11753+
Sum over requested axis.
11754+
11755+
See Also
11756+
--------
11757+
Series.sum : Return the sum over Series values.
11758+
DataFrame.mean : Return the mean of the values over the requested axis.
11759+
DataFrame.median : Return the median of the values over the requested axis.
11760+
DataFrame.mode : Get the mode(s) of each element along the requested axis.
11761+
DataFrame.std : Return the standard deviation of the values over the
11762+
requested axis.
11763+
11764+
Examples
11765+
--------
11766+
>>> idx = pd.MultiIndex.from_arrays(
11767+
... [["warm", "warm", "cold", "cold"], ["dog", "falcon", "fish", "spider"]],
11768+
... names=["blooded", "animal"],
11769+
... )
11770+
>>> s = pd.Series([4, 2, 0, 8], name="legs", index=idx)
11771+
>>> s
11772+
blooded animal
11773+
warm dog 4
11774+
falcon 2
11775+
cold fish 0
11776+
spider 8
11777+
Name: legs, dtype: int64
11778+
11779+
>>> s.sum()
11780+
14
11781+
11782+
By default, the sum of an empty or all-NA Series is ``0``.
11783+
11784+
>>> pd.Series([], dtype="float64").sum() # min_count=0 is the default
11785+
0.0
11786+
11787+
This can be controlled with the ``min_count`` parameter. For example, if
11788+
you'd like the sum of an empty series to be NaN, pass ``min_count=1``.
11789+
11790+
>>> pd.Series([], dtype="float64").sum(min_count=1)
11791+
nan
11792+
11793+
Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and
11794+
empty series identically.
11795+
11796+
>>> pd.Series([np.nan]).sum()
11797+
0.0
11798+
11799+
>>> pd.Series([np.nan]).sum(min_count=1)
11800+
nan
11801+
"""
1172111802
result = super().sum(
1172211803
axis=axis,
1172311804
skipna=skipna,

0 commit comments

Comments
 (0)