Skip to content

Commit

Permalink
docs(python): Add additional Series docstring examples (#13558)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-brink authored Jan 9, 2024
1 parent 26da007 commit 85e4f53
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,28 @@ def inner_dtype(self) -> DataType | None:

@property
def name(self) -> str:
"""Get the name of this Series."""
"""
Get the name of this Series.
Examples
--------
>>> s = pl.Series("a", [1, 2, 3])
>>> s.name
'a'
"""
return self._s.name()

@property
def shape(self) -> tuple[int]:
"""Shape of this Series."""
"""
Shape of this Series.
Examples
--------
>>> s = pl.Series("a", [1, 2, 3])
>>> s.shape
(3,)
"""
return (self._s.len(),)

def __bool__(self) -> NoReturn:
Expand Down Expand Up @@ -1877,7 +1893,15 @@ def mean(self) -> PythonLiteral | None:
return self._s.mean()

def product(self) -> int | float:
"""Reduce this Series to the product value."""
"""
Reduce this Series to the product value.
Examples
--------
>>> s = pl.Series("a", [1, 2, 3])
>>> s.product()
6
"""
return self._s.product()

def pow(self, exponent: int | float | None | Series) -> Series:
Expand Down Expand Up @@ -1940,6 +1964,16 @@ def nan_max(self) -> int | float | date | datetime | timedelta | str:
This differs from numpy's `nanmax` as numpy defaults to propagating NaN values,
whereas polars defaults to ignoring them.
Examples
--------
>>> s = pl.Series("a", [1, 3, 4])
>>> s.nan_max()
4
>>> s = pl.Series("a", [1, float("nan"), 4])
>>> s.nan_max()
nan
"""
return self.to_frame().select_seq(F.col(self.name).nan_max()).item()

Expand All @@ -1949,6 +1983,16 @@ def nan_min(self) -> int | float | date | datetime | timedelta | str:
This differs from numpy's `nanmax` as numpy defaults to propagating NaN values,
whereas polars defaults to ignoring them.
Examples
--------
>>> s = pl.Series("a", [1, 3, 4])
>>> s.nan_min()
1
>>> s = pl.Series("a", [1, float("nan"), 4])
>>> s.nan_min()
nan
"""
return self.to_frame().select_seq(F.col(self.name).nan_min()).item()

Expand Down Expand Up @@ -6887,7 +6931,19 @@ def get_chunks(self) -> list[Series]:
return self._s.get_chunks()

def implode(self) -> Self:
"""Aggregate values into a list."""
"""
Aggregate values into a list.
Examples
--------
>>> s = pl.Series("a", [1, 2, 3])
>>> s.implode()
shape: (1,)
Series: 'a' [list[i64]]
[
[1, 2, 3]
]
"""

@deprecate_renamed_function("map_elements", version="0.19.0")
def apply(
Expand Down

0 comments on commit 85e4f53

Please sign in to comment.