Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(python): Add additional Series docstring examples #13558

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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