Skip to content

Commit

Permalink
docs(python): Add a couple of docstring examples to Series methods (#…
Browse files Browse the repository at this point in the history
…13244)

Co-authored-by: Robin van den Brink <[email protected]>
  • Loading branch information
r-brink and Robin van den Brink authored Dec 26, 2023
1 parent 4d33079 commit a34a4f0
Showing 1 changed file with 121 additions and 5 deletions.
126 changes: 121 additions & 5 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,18 @@ def sqrt(self) -> Series:
1.414214
]
Examples
--------
>>> s = pl.Series([1, 2, 3])
>>> s.sqrt()
shape: (3,)
Series: '' [f64]
[
1.0
1.414214
1.732051
]
"""

def cbrt(self) -> Series:
Expand All @@ -1342,6 +1354,18 @@ def cbrt(self) -> Series:
1.259921
]
Examples
--------
>>> s = pl.Series([1, 2, 3])
>>> s.cbrt()
shape: (3,)
Series: '' [f64]
[
1.0
1.259921
1.44225
]
"""

@overload
Expand Down Expand Up @@ -1437,16 +1461,72 @@ def all(self, *, ignore_nulls: bool = True) -> bool | None:
return self._s.all(ignore_nulls=ignore_nulls)

def log(self, base: float = math.e) -> Series:
"""Compute the logarithm to a given base."""
"""
Compute the logarithm to a given base.
Examples
--------
>>> s = pl.Series([1, 2, 3])
>>> s.log()
shape: (3,)
Series: '' [f64]
[
0.0
0.693147
1.098612
]
"""

def log1p(self) -> Series:
"""Compute the natural logarithm of the input array plus one, element-wise."""
"""
Compute the natural logarithm of the input array plus one, element-wise.
Examples
--------
>>> s = pl.Series([1, 2, 3])
>>> s.log1p()
shape: (3,)
Series: '' [f64]
[
0.693147
1.098612
1.386294
]
"""

def log10(self) -> Series:
"""Compute the base 10 logarithm of the input array, element-wise."""
"""
Compute the base 10 logarithm of the input array, element-wise.
Examples
--------
>>> s = pl.Series([10, 100, 1000])
>>> s.log10()
shape: (3,)
Series: '' [f64]
[
1.0
2.0
3.0
]
"""

def exp(self) -> Series:
"""Compute the exponential, element-wise."""
"""
Compute the exponential, element-wise.
Examples
--------
>>> s = pl.Series([1, 2, 3])
>>> s.exp()
shape: (3,)
Series: '' [f64]
[
2.718282
7.389056
20.085537
]
"""

def drop_nulls(self) -> Series:
"""
Expand Down Expand Up @@ -3332,7 +3412,15 @@ def gather(
"""

def null_count(self) -> int:
"""Count the null values in this Series."""
"""
Count the null values in this Series.
Examples
--------
>>> s = pl.Series([1, None, None])
>>> s.null_count()
2
"""
return self._s.null_count()

def has_validity(self) -> bool:
Expand Down Expand Up @@ -3375,6 +3463,16 @@ def is_sorted(self, *, descending: bool = False) -> bool:
descending
Check if the Series is sorted in descending order
Examples
--------
>>> s = pl.Series([1, 3, 2])
>>> s.is_sorted()
False
>>> s = pl.Series([3, 2, 1])
>>> s.is_sorted(descending=True)
True
"""
return self._s.is_sorted(descending)

Expand Down Expand Up @@ -5908,6 +6006,18 @@ def abs(self) -> Series:
Compute absolute values.
Same as `abs(series)`.
Examples
--------
>>> s = pl.Series([1, -2, -3])
>>> s.abs()
shape: (3,)
Series: '' [i64]
[
1
2
3
]
"""

def rank(
Expand Down Expand Up @@ -6112,6 +6222,12 @@ def skew(self, *, bias: bool = True) -> float | None:
.. math::
G_1 = \frac{k_3}{k_2^{3/2}} = \frac{\sqrt{N(N-1)}}{N-2}\frac{m_3}{m_2^{3/2}}
Examples
--------
>>> s = pl.Series([1, 2, 2, 4, 5])
>>> s.skew()
0.34776706224699483
"""
return self._s.skew(bias)

Expand Down

0 comments on commit a34a4f0

Please sign in to comment.