Skip to content

Commit

Permalink
test: mark failing dask tests, add dask to constructor (narwhals-dev#697
Browse files Browse the repository at this point in the history
)
  • Loading branch information
aidoskanapyanov authored and montanarograziano committed Aug 2, 2024
1 parent 88a1ca9 commit 3820986
Show file tree
Hide file tree
Showing 67 changed files with 395 additions and 92 deletions.
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def pyarrow_table_constructor(obj: Any) -> IntoDataFrame:
if get_modin() is not None: # pragma: no cover
eager_constructors.append(modin_constructor)
# TODO(unassigned): when Dask gets better support, remove the "False and" part
if False and get_dask_dataframe() is not None: # pragma: no cover # noqa: SIM223
lazy_constructors.append(dask_lazy_constructor)
if get_dask_dataframe() is not None: # pragma: no cover
lazy_constructors.append(dask_lazy_constructor) # type: ignore # noqa: PGH003


@pytest.fixture(params=eager_constructors)
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/abs_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any

import pytest

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


def test_abs(constructor: Any) -> None:
def test_abs(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
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
6 changes: 5 additions & 1 deletion tests/expr_and_series/any_all_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any

import pytest

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


def test_any_all(constructor: Any) -> None:
def test_any_all(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(
constructor(
{
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/any_horizontal_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any

import pytest

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


def test_anyh(constructor: Any) -> None:
def test_anyh(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {
"a": [False, False, True],
"b": [False, True, True],
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/arg_true_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any

import pytest

import narwhals as nw
from tests.utils import compare_dicts


def test_arg_true(constructor: Any) -> None:
def test_arg_true(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor({"a": [1, None, None, 3]}))
result = df.select(nw.col("a").is_null().arg_true())
expected = {"a": [1, 2]}
Expand Down
32 changes: 28 additions & 4 deletions tests/expr_and_series/arithmetic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@
],
)
def test_arithmetic(
attr: str, rhs: Any, expected: list[Any], constructor: Any, request: Any
attr: str,
rhs: Any,
expected: list[Any],
constructor: Any,
request: Any,
) -> None:
if "dask" in str(constructor) and attr not in [
"__add__",
"__sub__",
"__mul__",
]:
request.applymarker(pytest.mark.xfail)
if attr == "__mod__" and any(
x in str(constructor) for x in ["pandas_pyarrow", "pyarrow_table", "modin"]
):
Expand All @@ -48,8 +58,14 @@ def test_arithmetic(
],
)
def test_right_arithmetic(
attr: str, rhs: Any, expected: list[Any], constructor: Any, request: Any
attr: str,
rhs: Any,
expected: list[Any],
constructor: Any,
request: Any,
) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if attr == "__rmod__" and any(
x in str(constructor) for x in ["pandas_pyarrow", "pyarrow_table", "modin"]
):
Expand All @@ -75,7 +91,11 @@ def test_right_arithmetic(
],
)
def test_arithmetic_series(
attr: str, rhs: Any, expected: list[Any], constructor_eager: Any, request: Any
attr: str,
rhs: Any,
expected: list[Any],
constructor_eager: Any,
request: Any,
) -> None:
if attr == "__mod__" and any(
x in str(constructor_eager) for x in ["pandas_pyarrow", "pyarrow_table", "modin"]
Expand All @@ -101,7 +121,11 @@ def test_arithmetic_series(
],
)
def test_right_arithmetic_series(
attr: str, rhs: Any, expected: list[Any], constructor_eager: Any, request: Any
attr: str,
rhs: Any,
expected: list[Any],
constructor_eager: Any,
request: Any,
) -> None:
if attr == "__rmod__" and any(
x in str(constructor_eager) for x in ["pandas_pyarrow", "pyarrow_table", "modin"]
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/cast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

@pytest.mark.filterwarnings("ignore:casting period[M] values to int64:FutureWarning")
def test_cast(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) <= (15,): # pragma: no cover
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/count_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any

import pytest

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


def test_count(constructor: Any) -> None:
def test_count(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
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
6 changes: 5 additions & 1 deletion tests/expr_and_series/cum_sum_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any

import pytest

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

Expand All @@ -10,7 +12,9 @@
}


def test_cum_sum_simple(constructor: Any) -> None:
def test_cum_sum_simple(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
result = df.select(nw.all().cum_sum())
expected = {
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@


def test_diff(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) < (13,):
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/double_selected_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any

import pytest

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


def test_double_selected(constructor: Any) -> None:
def test_double_selected(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor(data))

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

import pytest

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


def test_double(constructor: Any) -> None:
def test_double(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
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: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
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)
expected = {"o": [1, 3, 2], "a": [2, 6, 4], "b": [8, 8, 12], "z": [14.0, 16.0, 18.0]}
expected = {
"o": [1, 3, 2],
"a": [2, 6, 4],
"b": [8, 8, 12],
"z": [14.0, 16.0, 18.0],
}
compare_dicts(result, expected)
6 changes: 5 additions & 1 deletion tests/expr_and_series/drop_nulls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

from typing import Any

import pytest

import narwhals as nw
from tests.utils import compare_dicts


def test_drop_nulls(constructor: Any) -> None:
def test_drop_nulls(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {
"A": [1, 2, None, 4],
"B": [5, 6, 7, 8],
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/filter_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any

import pytest

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

Expand All @@ -11,7 +13,9 @@
}


def test_filter(constructor: Any) -> None:
def test_filter(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
result = df.select(nw.col("a").filter(nw.col("i") < 2, nw.col("c") == 5))
expected = {"a": [0]}
Expand Down
4 changes: 3 additions & 1 deletion tests/expr_and_series/gather_every_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

@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) -> None:
def test_gather_every_expr(constructor: Any, n: int, offset: int, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))

result = df.select(nw.col("a").gather_every(n=n, offset=offset))
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/is_between_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
("none", [False, True, True, False]),
],
)
def test_is_between(constructor: Any, closed: str, expected: list[bool]) -> None:
def test_is_between(
constructor: Any, closed: str, expected: list[bool], request: Any
) -> None:
if "dask" in str(constructor) and closed == "none":
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
result = df.select(nw.col("a").is_between(1, 5, closed=closed))
expected_dict = {"a": expected}
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_duplicated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


def test_is_duplicated_expr(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "modin" in str(constructor):
# TODO(unassigned): why is Modin failing here?
request.applymarker(pytest.mark.xfail)
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_first_distinct_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


def test_is_first_distinct_expr(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "modin" in str(constructor):
# TODO(unassigned): why is Modin failing here?
request.applymarker(pytest.mark.xfail)
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/is_in_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any

import pytest

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

Expand All @@ -9,7 +11,9 @@
}


def test_expr_is_in(constructor: Any) -> None:
def test_expr_is_in(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
result = df.select(nw.col("a").is_in([4, 5]))
expected = {"a": [False, True, False, True]}
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_last_distinct_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


def test_is_last_distinct_expr(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "modin" in str(constructor):
# TODO(unassigned): why is Modin failing here?
request.applymarker(pytest.mark.xfail)
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_unique_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


def test_is_unique_expr(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "modin" in str(constructor):
# TODO(unassigned): why is Modin failing here?
request.applymarker(pytest.mark.xfail)
Expand Down
6 changes: 5 additions & 1 deletion tests/expr_and_series/len_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from typing import Any

import pytest

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

data = {"a": list("xyz"), "b": [1, 2, 1]}
expected = {"a1": [2], "a2": [1]}


def test_len(constructor: Any) -> None:
def test_len(constructor: Any, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df_raw = constructor(data)
df = nw.from_native(df_raw).select(
nw.col("a").filter(nw.col("b") == 1).len().alias("a1"),
Expand Down
4 changes: 3 additions & 1 deletion tests/expr_and_series/max_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@


@pytest.mark.parametrize("expr", [nw.col("a", "b", "z").max(), nw.max("a", "b", "z")])
def test_expr_max_expr(constructor: Any, expr: nw.Expr) -> None:
def test_expr_max_expr(constructor: Any, expr: nw.Expr, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
result = df.select(expr)
expected = {"a": [3], "b": [6], "z": [9.0]}
Expand Down
4 changes: 3 additions & 1 deletion tests/expr_and_series/mean_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@


@pytest.mark.parametrize("expr", [nw.col("a", "b", "z").mean(), nw.mean("a", "b", "z")])
def test_expr_mean_expr(constructor: Any, expr: nw.Expr) -> None:
def test_expr_mean_expr(constructor: Any, expr: nw.Expr, request: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
result = df.select(expr)
expected = {"a": [2.0], "b": [5.0], "z": [8.0]}
Expand Down
Loading

0 comments on commit 3820986

Please sign in to comment.