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

feat: add ConstructorEager type #1091

Merged
merged 16 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions tests/expr_and_series/abs_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts


Expand All @@ -12,7 +11,7 @@ def test_abs(constructor: Constructor) -> None:
compare_dicts(result, expected)


def test_abs_series(constructor_eager: Any) -> None:
def test_abs_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager({"a": [1, 2, 3, -4, 5]}), eager_only=True)
result = {"b": df["a"].abs()}
expected = {"b": [1, 2, 3, 4, 5]}
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/all_horizontal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import narwhals.stable.v1 as nw
from narwhals.utils import parse_version
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts


Expand All @@ -23,7 +24,7 @@ def test_allh(constructor: Constructor, expr1: Any, expr2: Any) -> None:
compare_dicts(result, expected)


def test_allh_series(constructor_eager: Any) -> None:
def test_allh_series(constructor_eager: ConstructorEager) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/any_all_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts


Expand All @@ -23,7 +22,7 @@ def test_any_all(constructor: Constructor) -> None:
compare_dicts(result, expected)


def test_any_all_series(constructor_eager: Any) -> None:
def test_any_all_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(
constructor_eager(
{
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/arg_true_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any

import pytest

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts


Expand All @@ -16,7 +15,7 @@ def test_arg_true(constructor: Constructor, request: pytest.FixtureRequest) -> N
compare_dicts(result, expected)


def test_arg_true_series(constructor_eager: Any) -> None:
def test_arg_true_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager({"a": [1, None, None, 3]}), eager_only=True)
result = df.select(df["a"].is_null().arg_true())
expected = {"a": [1, 2]}
Expand Down
7 changes: 4 additions & 3 deletions tests/expr_and_series/arithmetic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import narwhals.stable.v1 as nw
from narwhals.utils import parse_version
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts


Expand Down Expand Up @@ -94,7 +95,7 @@ def test_arithmetic_series(
attr: str,
rhs: Any,
expected: list[Any],
constructor_eager: Any,
constructor_eager: ConstructorEager,
request: pytest.FixtureRequest,
) -> None:
if attr == "__mod__" and any(
Expand Down Expand Up @@ -124,7 +125,7 @@ def test_right_arithmetic_series(
attr: str,
rhs: Any,
expected: list[Any],
constructor_eager: Any,
constructor_eager: ConstructorEager,
request: pytest.FixtureRequest,
) -> None:
if attr == "__rmod__" and any(
Expand All @@ -139,7 +140,7 @@ def test_right_arithmetic_series(


def test_truediv_same_dims(
constructor_eager: Any, request: pytest.FixtureRequest
constructor_eager: ConstructorEager, request: pytest.FixtureRequest
) -> None:
if "polars" in str(constructor_eager):
# https://github.com/pola-rs/polars/issues/17760
Expand Down
7 changes: 4 additions & 3 deletions tests/expr_and_series/cat/get_categories_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from __future__ import annotations

from typing import Any

import pyarrow as pa
import pytest

import narwhals.stable.v1 as nw
from narwhals.utils import parse_version
from tests.utils import ConstructorEager
from tests.utils import compare_dicts

data = {"a": ["one", "two", "two"]}


def test_get_categories(request: pytest.FixtureRequest, constructor_eager: Any) -> None:
def test_get_categories(
request: pytest.FixtureRequest, constructor_eager: ConstructorEager
) -> None:
if "pyarrow_table" in str(constructor_eager) and parse_version(
pa.__version__
) < parse_version("15.0.0"):
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/clip_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts


Expand All @@ -20,7 +19,7 @@ def test_clip(constructor: Constructor) -> None:
compare_dicts(result, expected)


def test_clip_series(constructor_eager: Any) -> None:
def test_clip_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager({"a": [1, 2, 3, -4, 5]}), eager_only=True)
result = {
"lower_only": df["a"].clip(lower_bound=3),
Expand Down
11 changes: 8 additions & 3 deletions tests/expr_and_series/convert_time_zone_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

from datetime import datetime
from datetime import timezone
from typing import Any
from typing import TYPE_CHECKING

import pandas as pd
import polars as pl
Expand All @@ -13,6 +15,9 @@
from tests.utils import compare_dicts
from tests.utils import is_windows

if TYPE_CHECKING:
from tests.utils import ConstructorEager


def test_convert_time_zone(
constructor: Constructor, request: pytest.FixtureRequest
Expand Down Expand Up @@ -43,7 +48,7 @@ def test_convert_time_zone(


def test_convert_time_zone_series(
constructor_eager: Any, request: pytest.FixtureRequest
constructor_eager: ConstructorEager, request: pytest.FixtureRequest
) -> None:
if (
(any(x in str(constructor_eager) for x in ("pyarrow", "modin")) and is_windows())
Expand Down Expand Up @@ -116,7 +121,7 @@ def test_convert_time_zone_to_none(constructor: Constructor) -> None:
df.select(nw.col("a").dt.convert_time_zone(None)) # type: ignore[arg-type]


def test_convert_time_zone_to_none_series(constructor_eager: Any) -> None:
def test_convert_time_zone_to_none_series(constructor_eager: ConstructorEager) -> None:
data = {
"a": [
datetime(2020, 1, 1, tzinfo=timezone.utc),
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/count_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts


Expand All @@ -13,7 +12,7 @@ def test_count(constructor: Constructor) -> None:
compare_dicts(result, expected)


def test_count_series(constructor_eager: Any) -> None:
def test_count_series(constructor_eager: ConstructorEager) -> None:
data = {"a": [1, 3, 2], "b": [4, None, 6], "z": [7.0, None, None]}
df = nw.from_native(constructor_eager(data), eager_only=True)
result = {"a": [df["a"].count()], "b": [df["b"].count()], "z": [df["z"].count()]}
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/cum_sum_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts

data = {
Expand All @@ -22,7 +21,7 @@ def test_cum_sum_simple(constructor: Constructor) -> None:
compare_dicts(result, expected)


def test_cum_sum_simple_series(constructor_eager: Any) -> None:
def test_cum_sum_simple_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)
expected = {
"a": [0, 1, 3, 6, 10],
Expand Down
7 changes: 4 additions & 3 deletions tests/expr_and_series/diff_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Any

import pyarrow as pa
import pytest

import narwhals.stable.v1 as nw
from narwhals.utils import parse_version
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts

data = {
Expand All @@ -32,7 +31,9 @@ def test_diff(constructor: Constructor, request: pytest.FixtureRequest) -> None:
compare_dicts(result, expected)


def test_diff_series(constructor_eager: Any, request: pytest.FixtureRequest) -> None:
def test_diff_series(
constructor_eager: ConstructorEager, request: pytest.FixtureRequest
) -> None:
if "pyarrow_table_constructor" in str(constructor_eager) and parse_version(
pa.__version__
) < (13,):
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/drop_nulls_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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 ConstructorEager
from tests.utils import compare_dicts


Expand Down Expand Up @@ -36,7 +35,7 @@ def test_drop_nulls(constructor: Constructor, request: pytest.FixtureRequest) ->
compare_dicts(result_d, expected_d)


def test_drop_nulls_series(constructor_eager: Any) -> None:
def test_drop_nulls_series(constructor_eager: ConstructorEager) -> None:
data = {
"A": [1, 2, None, 4],
"B": [5, 6, 7, 8],
Expand Down
6 changes: 3 additions & 3 deletions tests/expr_and_series/dt/datetime_attributes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from datetime import date
from datetime import datetime
from typing import Any

import pytest

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts

data = {
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_datetime_attributes(
)
def test_datetime_attributes_series(
request: pytest.FixtureRequest,
constructor_eager: Any,
constructor_eager: ConstructorEager,
attribute: str,
expected: list[int],
) -> None:
Expand All @@ -91,7 +91,7 @@ def test_datetime_attributes_series(


def test_datetime_chained_attributes(
request: pytest.FixtureRequest, constructor_eager: Any
request: pytest.FixtureRequest, constructor_eager: ConstructorEager
) -> None:
if "pandas" in str(constructor_eager) and "pyarrow" not in str(constructor_eager):
request.applymarker(pytest.mark.xfail)
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/dt/datetime_duration_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from datetime import timedelta
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -12,6 +11,7 @@
import narwhals.stable.v1 as nw
from narwhals.utils import parse_version
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts

data = {
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_duration_attributes(
)
def test_duration_attributes_series(
request: pytest.FixtureRequest,
constructor_eager: Any,
constructor_eager: ConstructorEager,
attribute: str,
expected_a: list[int],
expected_b: list[int],
Expand Down
7 changes: 4 additions & 3 deletions tests/expr_and_series/dt/to_string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts
from tests.utils import is_windows

Expand All @@ -29,7 +30,7 @@
],
)
@pytest.mark.skipif(is_windows(), reason="pyarrow breaking on windows")
def test_dt_to_string_series(constructor_eager: Any, fmt: str) -> None:
def test_dt_to_string_series(constructor_eager: ConstructorEager, fmt: str) -> None:
input_frame = nw.from_native(constructor_eager(data), eager_only=True)
input_series = input_frame["a"]

Expand Down Expand Up @@ -100,7 +101,7 @@ def _clean_string_expr(e: Any) -> Any:
)
@pytest.mark.skipif(is_windows(), reason="pyarrow breaking on windows")
def test_dt_to_string_iso_local_datetime_series(
constructor_eager: Any, data: datetime, expected: str
constructor_eager: ConstructorEager, data: datetime, expected: str
) -> None:
df = constructor_eager({"a": [data]})
result = (
Expand Down Expand Up @@ -152,7 +153,7 @@ def test_dt_to_string_iso_local_datetime_expr(
)
@pytest.mark.skipif(is_windows(), reason="pyarrow breaking on windows")
def test_dt_to_string_iso_local_date_series(
constructor_eager: Any, data: datetime, expected: str
constructor_eager: ConstructorEager, data: datetime, expected: str
) -> None:
df = constructor_eager({"a": [data]})
result = nw.from_native(df, eager_only=True)["a"].dt.to_string("%Y-%m-%d").item(0)
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/fill_null_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts

data = {
Expand All @@ -23,7 +22,7 @@ def test_fill_null(constructor: Constructor) -> None:
compare_dicts(result, expected)


def test_fill_null_series(constructor_eager: Any) -> None:
def test_fill_null_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)

expected = {
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/filter_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any

import pytest

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
from tests.utils import compare_dicts

data = {
Expand All @@ -23,7 +22,7 @@ def test_filter(constructor: Constructor, request: pytest.FixtureRequest) -> Non
compare_dicts(result, expected)


def test_filter_series(constructor_eager: Any) -> None:
def test_filter_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.select(df["a"].filter((df["i"] < 2) & (df["c"] == 5)))
expected = {"a": [0]}
Expand Down
Loading
Loading