-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Expr and Series log and log10 methods
- Loading branch information
Showing
11 changed files
with
290 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
- is_null | ||
- is_unique | ||
- len | ||
- log | ||
- log10 | ||
- max | ||
- mean | ||
- min | ||
|
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 |
---|---|---|
|
@@ -33,6 +33,8 @@ | |
- is_unique | ||
- item | ||
- len | ||
- log | ||
- log10 | ||
- max | ||
- mean | ||
- min | ||
|
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
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,28 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
from tests.utils import Constructor | ||
from tests.utils import compare_dicts | ||
|
||
data = {"a": [-1, 0, 1, 10, 100.0]} | ||
|
||
|
||
def test_log_expr(constructor: Constructor, request: pytest.FixtureRequest) -> None: | ||
if "dask" in str(constructor): | ||
request.applymarker(pytest.mark.xfail) | ||
|
||
df = nw.from_native(constructor(data)) | ||
result = df.select(nw.col("a").log10()) | ||
expected = {"a": [float("nan"), float("-inf"), 0, 1, 2]} | ||
compare_dicts(result, expected) | ||
|
||
|
||
def test_log_series(constructor_eager: Any) -> None: | ||
series = nw.from_native(constructor_eager(data), eager_only=True)["a"] | ||
result = series.log10() | ||
expected = {"a": [float("nan"), float("-inf"), 0, 1, 2]} | ||
compare_dicts({"a": result}, expected) |
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,28 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
from tests.utils import Constructor | ||
from tests.utils import compare_dicts | ||
|
||
data = {"a": [-1, 0, 1, 2, 4.0]} | ||
|
||
|
||
def test_log_expr(constructor: Constructor, request: pytest.FixtureRequest) -> None: | ||
if "dask" in str(constructor): | ||
request.applymarker(pytest.mark.xfail) | ||
|
||
df = nw.from_native(constructor(data)) | ||
result = df.select(nw.col("a").log(base=2)) | ||
expected = {"a": [float("nan"), float("-inf"), 0, 1, 2]} | ||
compare_dicts(result, expected) | ||
|
||
|
||
def test_log_series(constructor_eager: Any) -> None: | ||
series = nw.from_native(constructor_eager(data), eager_only=True)["a"] | ||
result = series.log(base=2) | ||
expected = {"a": [float("nan"), float("-inf"), 0, 1, 2]} | ||
compare_dicts({"a": result}, expected) |