-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh: series and expr round method (#306)
* enh: series and expr round * Update narwhals/_pandas_like/expr.py Francesco always forgets this Co-authored-by: Marco Edward Gorelli <[email protected]> * Update narwhals/_pandas_like/series.py Co-authored-by: Marco Edward Gorelli <[email protected]> * move test to expr folder * note on different rounding * Update narwhals/expression.py * Update narwhals/series.py --------- Co-authored-by: Marco Edward Gorelli <[email protected]>
- Loading branch information
1 parent
057daad
commit 2c29d05
Showing
7 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
- n_unique | ||
- over | ||
- quantile | ||
- round | ||
- sample | ||
- shift | ||
- sort | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
- null_count | ||
- n_unique | ||
- quantile | ||
- round | ||
- sample | ||
- shape | ||
- shift | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import pandas as pd | ||
import polars as pl | ||
import pytest | ||
|
||
import narwhals as nw | ||
from tests.utils import compare_dicts | ||
|
||
|
||
@pytest.mark.parametrize("constructor", [pd.DataFrame, pl.DataFrame]) | ||
@pytest.mark.parametrize("decimals", [0, 1, 2]) | ||
def test_round(constructor: Any, decimals: int) -> None: | ||
data = {"a": [1.12345, 2.56789, 3.901234]} | ||
df_raw = constructor(data) | ||
df = nw.from_native(df_raw, eager_only=True) | ||
|
||
expected_data = {k: [round(e, decimals) for e in v] for k, v in data.items()} | ||
result_frame = df.select(nw.col("a").round(decimals)) | ||
compare_dicts(result_frame, expected_data) | ||
|
||
result_series = df["a"].round(decimals) | ||
|
||
assert result_series.to_numpy().tolist() == expected_data["a"] |