Skip to content

Commit 463eb6e

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.DataFrame.sum (#58565)
* DOC: add RT03 for pandas.DataFrame.sum * DOC: remove redundant space
1 parent 5beadb7 commit 463eb6e

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

ci/code_checks.sh

-1
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.Grouper PR02" \
8281
-i "pandas.Index PR07" \

pandas/core/frame.py

+81-1
Original file line numberDiff line numberDiff line change
@@ -11744,7 +11744,6 @@ def max(
1174411744
return result
1174511745

1174611746
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="sum")
11747-
@doc(make_doc("sum", ndim=2))
1174811747
def sum(
1174911748
self,
1175011749
axis: Axis | None = 0,
@@ -11753,6 +11752,87 @@ def sum(
1175311752
min_count: int = 0,
1175411753
**kwargs,
1175511754
) -> Series:
11755+
"""
11756+
Return the sum of the values over the requested axis.
11757+
11758+
This is equivalent to the method ``numpy.sum``.
11759+
11760+
Parameters
11761+
----------
11762+
axis : {index (0), columns (1)}
11763+
Axis for the function to be applied on.
11764+
For `Series` this parameter is unused and defaults to 0.
11765+
11766+
.. warning::
11767+
11768+
The behavior of DataFrame.sum with ``axis=None`` is deprecated,
11769+
in a future version this will reduce over both axes and return a scalar
11770+
To retain the old behavior, pass axis=0 (or do not pass axis).
11771+
11772+
.. versionadded:: 2.0.0
11773+
11774+
skipna : bool, default True
11775+
Exclude NA/null values when computing the result.
11776+
numeric_only : bool, default False
11777+
Include only float, int, boolean columns. Not implemented for Series.
11778+
min_count : int, default 0
11779+
The required number of valid values to perform the operation. If fewer than
11780+
``min_count`` non-NA values are present the result will be NA.
11781+
**kwargs
11782+
Additional keyword arguments to be passed to the function.
11783+
11784+
Returns
11785+
-------
11786+
Series or scalar
11787+
Sum over requested axis.
11788+
11789+
See Also
11790+
--------
11791+
Series.sum : Return the sum over Series values.
11792+
DataFrame.mean : Return the mean of the values over the requested axis.
11793+
DataFrame.median : Return the median of the values over the requested axis.
11794+
DataFrame.mode : Get the mode(s) of each element along the requested axis.
11795+
DataFrame.std : Return the standard deviation of the values over the
11796+
requested axis.
11797+
11798+
Examples
11799+
--------
11800+
>>> idx = pd.MultiIndex.from_arrays(
11801+
... [["warm", "warm", "cold", "cold"], ["dog", "falcon", "fish", "spider"]],
11802+
... names=["blooded", "animal"],
11803+
... )
11804+
>>> s = pd.Series([4, 2, 0, 8], name="legs", index=idx)
11805+
>>> s
11806+
blooded animal
11807+
warm dog 4
11808+
falcon 2
11809+
cold fish 0
11810+
spider 8
11811+
Name: legs, dtype: int64
11812+
11813+
>>> s.sum()
11814+
14
11815+
11816+
By default, the sum of an empty or all-NA Series is ``0``.
11817+
11818+
>>> pd.Series([], dtype="float64").sum() # min_count=0 is the default
11819+
0.0
11820+
11821+
This can be controlled with the ``min_count`` parameter. For example, if
11822+
you'd like the sum of an empty series to be NaN, pass ``min_count=1``.
11823+
11824+
>>> pd.Series([], dtype="float64").sum(min_count=1)
11825+
nan
11826+
11827+
Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and
11828+
empty series identically.
11829+
11830+
>>> pd.Series([np.nan]).sum()
11831+
0.0
11832+
11833+
>>> pd.Series([np.nan]).sum(min_count=1)
11834+
nan
11835+
"""
1175611836
result = super().sum(
1175711837
axis=axis,
1175811838
skipna=skipna,

0 commit comments

Comments
 (0)