Skip to content

Commit 3f8f704

Browse files
DOC: add RT03 and fix EX01 for pandas.Series.sum (#58778)
DOC: add RT03 for pandas.Series.sum
1 parent ab12958 commit 3f8f704

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
216216
-i "pandas.Series.str.wrap RT03,SA01" \
217217
-i "pandas.Series.str.zfill RT03" \
218218
-i "pandas.Series.struct.dtypes SA01" \
219-
-i "pandas.Series.sum RT03" \
220219
-i "pandas.Series.to_dict SA01" \
221220
-i "pandas.Series.to_frame SA01" \
222221
-i "pandas.Series.to_markdown SA01" \

pandas/core/series.py

+83-1
Original file line numberDiff line numberDiff line change
@@ -6647,7 +6647,6 @@ def max(
66476647
)
66486648

66496649
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="sum")
6650-
@doc(make_doc("sum", ndim=1))
66516650
def sum(
66526651
self,
66536652
axis: Axis | None = None,
@@ -6656,6 +6655,89 @@ def sum(
66566655
min_count: int = 0,
66576656
**kwargs,
66586657
):
6658+
"""
6659+
Return the sum of the values over the requested axis.
6660+
6661+
This is equivalent to the method ``numpy.sum``.
6662+
6663+
Parameters
6664+
----------
6665+
axis : {index (0)}
6666+
Axis for the function to be applied on.
6667+
For `Series` this parameter is unused and defaults to 0.
6668+
6669+
.. warning::
6670+
6671+
The behavior of DataFrame.sum with ``axis=None`` is deprecated,
6672+
in a future version this will reduce over both axes and return a scalar
6673+
To retain the old behavior, pass axis=0 (or do not pass axis).
6674+
6675+
.. versionadded:: 2.0.0
6676+
6677+
skipna : bool, default True
6678+
Exclude NA/null values when computing the result.
6679+
numeric_only : bool, default False
6680+
Include only float, int, boolean columns. Not implemented for Series.
6681+
6682+
min_count : int, default 0
6683+
The required number of valid values to perform the operation. If fewer than
6684+
``min_count`` non-NA values are present the result will be NA.
6685+
**kwargs
6686+
Additional keyword arguments to be passed to the function.
6687+
6688+
Returns
6689+
-------
6690+
scalar or Series (if level specified)
6691+
Median of the values for the requested axis.
6692+
6693+
See Also
6694+
--------
6695+
numpy.sum : Equivalent numpy function for computing sum.
6696+
Series.mean : Mean of the values.
6697+
Series.median : Median of the values.
6698+
Series.std : Standard deviation of the values.
6699+
Series.var : Variance of the values.
6700+
Series.min : Minimum value.
6701+
Series.max : Maximum value.
6702+
6703+
Examples
6704+
--------
6705+
>>> idx = pd.MultiIndex.from_arrays(
6706+
... [["warm", "warm", "cold", "cold"], ["dog", "falcon", "fish", "spider"]],
6707+
... names=["blooded", "animal"],
6708+
... )
6709+
>>> s = pd.Series([4, 2, 0, 8], name="legs", index=idx)
6710+
>>> s
6711+
blooded animal
6712+
warm dog 4
6713+
falcon 2
6714+
cold fish 0
6715+
spider 8
6716+
Name: legs, dtype: int64
6717+
6718+
>>> s.sum()
6719+
14
6720+
6721+
By default, the sum of an empty or all-NA Series is ``0``.
6722+
6723+
>>> pd.Series([], dtype="float64").sum() # min_count=0 is the default
6724+
0.0
6725+
6726+
This can be controlled with the ``min_count`` parameter. For example, if
6727+
you'd like the sum of an empty series to be NaN, pass ``min_count=1``.
6728+
6729+
>>> pd.Series([], dtype="float64").sum(min_count=1)
6730+
nan
6731+
6732+
Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and
6733+
empty series identically.
6734+
6735+
>>> pd.Series([np.nan]).sum()
6736+
0.0
6737+
6738+
>>> pd.Series([np.nan]).sum(min_count=1)
6739+
nan
6740+
"""
66596741
return NDFrame.sum(
66606742
self,
66616743
axis=axis,

0 commit comments

Comments
 (0)