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

test: replace type Any for constructor in all tests #962

Merged
merged 9 commits into from
Sep 13, 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
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pytest-cov
pytest-env
hypothesis
scikit-learn
typing_extensions
dask[dataframe]; python_version >= '3.9'
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from narwhals.typing import IntoDataFrame
from narwhals.typing import IntoFrame
from narwhals.utils import parse_version
from tests.utils import Constructor

with contextlib.suppress(ImportError):
import modin.pandas # noqa: F401
Expand Down Expand Up @@ -112,5 +113,5 @@ def constructor_eager(request: pytest.FixtureRequest) -> Callable[[Any], IntoDat


@pytest.fixture(params=[*eager_constructors, *lazy_constructors])
def constructor(request: pytest.FixtureRequest) -> Callable[[Any], Any]:
def constructor(request: pytest.FixtureRequest) -> Constructor:
return request.param # type: ignore[no-any-return]
3 changes: 2 additions & 1 deletion tests/expr_and_series/abs_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Any

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


def test_abs(constructor: Any) -> None:
def test_abs(constructor: Constructor) -> None:
df = nw.from_native(constructor({"a": [1, 2, 3, -4, 5]}))
result = df.select(b=nw.col("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 @@ -3,12 +3,13 @@
import pytest

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


@pytest.mark.parametrize("expr1", ["a", nw.col("a")])
@pytest.mark.parametrize("expr2", ["b", nw.col("b")])
def test_allh(constructor: Any, expr1: Any, expr2: Any) -> None:
def test_allh(constructor: Constructor, expr1: Any, expr2: Any) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/any_all_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Any

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


def test_any_all(constructor: Any) -> None:
def test_any_all(constructor: Constructor) -> None:
df = nw.from_native(
constructor(
{
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/any_horizontal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import pytest

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


@pytest.mark.parametrize("expr1", ["a", nw.col("a")])
@pytest.mark.parametrize("expr2", ["b", nw.col("b")])
def test_anyh(constructor: Any, expr1: Any, expr2: Any) -> None:
def test_anyh(constructor: Constructor, expr1: Any, expr2: Any) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/arg_true_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import pytest

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


def test_arg_true(constructor: Any, request: pytest.FixtureRequest) -> None:
def test_arg_true(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor({"a": [1, None, None, 3]}))
Expand Down
5 changes: 3 additions & 2 deletions tests/expr_and_series/arithmetic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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


Expand All @@ -32,7 +33,7 @@ def test_arithmetic_expr(
attr: str,
rhs: Any,
expected: list[Any],
constructor: Any,
constructor: Constructor,
request: pytest.FixtureRequest,
) -> None:
if attr == "__mod__" and any(
Expand Down Expand Up @@ -62,7 +63,7 @@ def test_right_arithmetic_expr(
attr: str,
rhs: Any,
expected: list[Any],
constructor: Any,
constructor: Constructor,
request: pytest.FixtureRequest,
) -> None:
if attr == "__rmod__" and any(
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/binary_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Any

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


def test_expr_binary(constructor: Any) -> None:
def test_expr_binary(constructor: Constructor) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df_raw = constructor(data)
result = nw.from_native(df_raw).with_columns(
Expand Down
9 changes: 4 additions & 5 deletions tests/expr_and_series/cast_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Any

import pandas as pd
import pyarrow as pa
import pytest

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

data = {
"a": [1],
Expand Down Expand Up @@ -46,7 +45,7 @@


@pytest.mark.filterwarnings("ignore:casting period[M] values to int64:FutureWarning")
def test_cast(constructor: Any, request: pytest.FixtureRequest) -> None:
def test_cast(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) <= (15,): # pragma: no cover
Expand Down Expand Up @@ -96,7 +95,7 @@ def test_cast(constructor: Any, request: pytest.FixtureRequest) -> None:
assert dict(result.collect_schema()) == expected


def test_cast_series(constructor: Any, request: pytest.FixtureRequest) -> None:
def test_cast_series(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) <= (15,): # pragma: no cover
Expand Down Expand Up @@ -163,7 +162,7 @@ def test_cast_string() -> None:


def test_cast_raises_for_unknown_dtype(
constructor: Any, request: pytest.FixtureRequest
constructor: Constructor, request: pytest.FixtureRequest
) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/clip_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Any

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


def test_clip(constructor: Any) -> None:
def test_clip(constructor: Constructor) -> None:
df = nw.from_native(constructor({"a": [1, 2, 3, -4, 5]}))
result = df.select(
lower_only=nw.col("a").clip(lower_bound=3),
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/count_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Any

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


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

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

data = {
Expand All @@ -10,7 +11,7 @@
}


def test_cum_sum_simple(constructor: Any) -> None:
def test_cum_sum_simple(constructor: Constructor) -> None:
df = nw.from_native(constructor(data))
result = df.select(nw.col("a", "b", "c").cum_sum())
expected = {
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

data = {
Expand All @@ -14,7 +15,7 @@
}


def test_diff(constructor: Any, request: pytest.FixtureRequest) -> None:
def test_diff(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) < (13,):
Expand Down
5 changes: 2 additions & 3 deletions tests/expr_and_series/double_selected_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Any

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


def test_double_selected(constructor: Any) -> None:
def test_double_selected(constructor: Constructor) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor(data))

Expand Down
7 changes: 3 additions & 4 deletions tests/expr_and_series/double_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from typing import Any

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


def test_double(constructor: Any) -> None:
def test_double(constructor: Constructor) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor(data))
result = df.with_columns(nw.all() * 2)
expected = {"a": [2, 6, 4], "b": [8, 8, 12], "z": [14.0, 16.0, 18.0]}
compare_dicts(result, expected)


def test_double_alias(constructor: Any) -> None:
def test_double_alias(constructor: Constructor) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor(data))
result = df.with_columns(nw.col("a").alias("o"), nw.all() * 2)
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/drop_nulls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import pytest

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


def test_drop_nulls(constructor: Any, request: pytest.FixtureRequest) -> None:
def test_drop_nulls(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/dt/datetime_attributes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

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

data = {
Expand Down Expand Up @@ -34,7 +35,10 @@
],
)
def test_datetime_attributes(
request: pytest.FixtureRequest, constructor: Any, attribute: str, expected: list[int]
request: pytest.FixtureRequest,
constructor: Constructor,
attribute: str,
expected: list[int],
) -> None:
if (
attribute == "date"
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/dt/datetime_duration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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

data = {
Expand Down Expand Up @@ -38,7 +39,7 @@
)
def test_duration_attributes(
request: pytest.FixtureRequest,
constructor: Any,
constructor: Constructor,
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 @@ -6,6 +6,7 @@
import pytest

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

Expand Down Expand Up @@ -57,7 +58,7 @@ def test_dt_to_string_series(constructor_eager: Any, fmt: str) -> None:
],
)
@pytest.mark.skipif(is_windows(), reason="pyarrow breaking on windows")
def test_dt_to_string_expr(constructor: Any, fmt: str) -> None:
def test_dt_to_string_expr(constructor: Constructor, fmt: str) -> None:
input_frame = nw.from_native(constructor(data))

expected_col = [datetime.strftime(d, fmt) for d in data["a"]]
Expand Down Expand Up @@ -130,7 +131,7 @@ def test_dt_to_string_iso_local_datetime_series(
)
@pytest.mark.skipif(is_windows(), reason="pyarrow breaking on windows")
def test_dt_to_string_iso_local_datetime_expr(
constructor: Any, data: datetime, expected: str
constructor: Constructor, data: datetime, expected: str
) -> None:
df = constructor({"a": [data]})

Expand Down Expand Up @@ -164,7 +165,7 @@ def test_dt_to_string_iso_local_date_series(
)
@pytest.mark.skipif(is_windows(), reason="pyarrow breaking on windows")
def test_dt_to_string_iso_local_date_expr(
constructor: Any, data: datetime, expected: str
constructor: Constructor, data: datetime, expected: str
) -> None:
df = constructor({"a": [data]})
result = nw.from_native(df).with_columns(
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/fill_null_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

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

data = {
Expand All @@ -10,7 +11,7 @@
}


def test_fill_null(constructor: Any) -> None:
def test_fill_null(constructor: Constructor) -> None:
df = nw.from_native(constructor(data))

result = df.with_columns(nw.col("a", "b", "c").fill_null(99))
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

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

data = {
Expand All @@ -13,7 +14,7 @@
}


def test_filter(constructor: Any, request: pytest.FixtureRequest) -> None:
def test_filter(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
Expand Down
3 changes: 2 additions & 1 deletion tests/expr_and_series/gather_every_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

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

data = {"a": list(range(10))}
Expand All @@ -11,7 +12,7 @@
@pytest.mark.parametrize("n", [1, 2, 3])
@pytest.mark.parametrize("offset", [1, 2, 3])
def test_gather_every_expr(
constructor: Any, n: int, offset: int, request: pytest.FixtureRequest
constructor: Constructor, n: int, offset: int, request: pytest.FixtureRequest
) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
Expand Down
Loading
Loading