Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Nov 9, 2023
1 parent a5b6dac commit 798848d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion crates/polars-plan/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ impl Expr {
self.map_private(FunctionExpr::Round { decimals })
}

/// Round underlying floating point array to given significant figures.
/// Round to a number of significant figures.
#[cfg(feature = "round_series")]
pub fn round_sig_figs(self, digits: i32) -> Self {
self.map_private(FunctionExpr::RoundSF { digits })
Expand Down
31 changes: 15 additions & 16 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,28 +1788,27 @@ def round(self, decimals: int = 0) -> Self:

def round_sig_figs(self, digits: int) -> Self:
"""
Round underlying floating point data by `decimals` digits.
Round to a number of significant figures.
Parameters
----------
significant_figures
Number of significant figures to round by.
digits
Number of significant figures to round to.
Examples
--------
>>> df = pl.DataFrame({"a": [0.33, 0.52, 1.02, 1.17]})
>>> df.select(pl.col("a").round_sig_figs(2))
shape: (4, 1)
┌──────┐
│ a │
│ --- │
│ f64 │
╞══════╡
│ 0.33 │
│ 0.52 │
│ 1.0 │
│ 1.2 │
└──────┘
>>> df = pl.DataFrame({"a": [0.01234, 3.333, 1234.0]})
>>> df.with_columns(pl.col("a").round_sig_figs(2).alias("round_sig_figs"))
shape: (3, 2)
┌─────────┬────────────────┐
│ a ┆ round_sig_figs │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞═════════╪════════════════╡
│ 0.01234 ┆ 0.012 │
│ 3.333 ┆ 3.3 │
│ 1234.0 ┆ 1200.0 │
└─────────┴────────────────┘
"""
return self._from_pyexpr(self._pyexpr.round_sig_figs(digits))
Expand Down
22 changes: 11 additions & 11 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4698,25 +4698,25 @@ def round(self, decimals: int = 0) -> Series:

def round_sig_figs(self, digits: int) -> Series:
"""
Round underlying floating point data by `significant` figures.
Round to a number of significant figures.
Parameters
----------
digits
Number of significant figures to round to.
Examples
--------
>>> s = pl.Series("a", [0.12345, 2.56789, 39.01234])
>>> s = pl.Series([0.01234, 3.333, 1234.0])
>>> s.round_sig_figs(2)
shape: (3,)
Series: 'a' [f64]
Series: '' [f64]
[
0.12
2.6
39.0
0.012
3.3
1200.0
]
Parameters
----------
digits
number of significant figures to round by.
"""

def dot(self, other: Series | ArrayLike) -> float | None:
Expand Down

0 comments on commit 798848d

Please sign in to comment.