Skip to content

Commit

Permalink
Merge pull request #124 from georgescutelnicu/series_sum
Browse files Browse the repository at this point in the history
Add docstring for Series.sum()
  • Loading branch information
MarcoGorelli authored May 9, 2024
2 parents 270b1d0 + 745ecb5 commit d15340d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions narwhals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ def max(self) -> Any:
return self._series.max()

def sum(self) -> Any:
"""
Reduce this Series to the sum value.
Examples:
>>> import pandas as pd
>>> import polars as pl
>>> import narwhals as nw
>>> s = [1, 2, 3]
>>> s_pd = pd.Series(s)
>>> s_pl = pl.Series(s)
We define a library agnostic function:
>>> def func(s_any):
... s = nw.from_native(s_any, series_only=True)
... return s.sum()
We can then pass either pandas or Polars to `func`:
>>> func(s_pd)
6
>>> func(s_pl)
6
"""
return self._series.sum()

def std(self, *, ddof: int = 1) -> Any:
Expand Down

0 comments on commit d15340d

Please sign in to comment.