Skip to content

Commit 81edd31

Browse files
authored
chore: more v1 test suite cleanups (#2822)
1 parent dd1feed commit 81edd31

File tree

9 files changed

+44
-58
lines changed

9 files changed

+44
-58
lines changed

tests/dependencies/is_narwhals_dataframe_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import TYPE_CHECKING
44

55
import narwhals as nw
6-
import narwhals.stable.v1 as nw_v1
76
from narwhals.stable.v1.dependencies import is_narwhals_dataframe
87

98
if TYPE_CHECKING:
@@ -14,5 +13,4 @@ def test_is_narwhals_dataframe(constructor_eager: ConstructorEager) -> None:
1413
df = constructor_eager({"col1": [1, 2], "col2": [3, 4]})
1514

1615
assert is_narwhals_dataframe(nw.from_native(df))
17-
assert is_narwhals_dataframe(nw_v1.from_native(df))
1816
assert not is_narwhals_dataframe(df)

tests/dependencies/is_narwhals_series_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import TYPE_CHECKING
44

55
import narwhals as nw
6-
import narwhals.stable.v1 as nw_v1
76
from narwhals.stable.v1.dependencies import is_narwhals_series
87

98
if TYPE_CHECKING:
@@ -14,5 +13,4 @@ def test_is_narwhals_series(constructor_eager: ConstructorEager) -> None:
1413
df = constructor_eager({"col1": [1, 2], "col2": [3, 4]})
1514

1615
assert is_narwhals_series(nw.from_native(df, eager_only=True)["col1"])
17-
assert is_narwhals_series(nw_v1.from_native(df, eager_only=True)["col1"])
1816
assert not is_narwhals_series(nw.from_native(df, eager_only=True)["col1"].to_native())

tests/expr_and_series/order_dependent_lazy_test.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
from typing import TYPE_CHECKING
44

5-
import pandas as pd
65
import pytest
76

87
import narwhals as nw
9-
import narwhals.stable.v1 as nw_v1
108
from narwhals.exceptions import InvalidOperationError
11-
from tests.utils import assert_equal_data
129

1310
if TYPE_CHECKING:
1411
from tests.utils import Constructor
@@ -29,35 +26,3 @@ def test_order_dependent_raises_in_lazy(constructor: Constructor) -> None:
2926
for agg in ["any", "all"]:
3027
with pytest.raises(InvalidOperationError, match="Order-dependent expressions"):
3128
lf.select(getattr((nw.col("a").diff() > 0), agg)())
32-
33-
34-
def test_dask_order_dependent_ops() -> None:
35-
# Preserve these for narwhals.stable.v1, even though they
36-
# raise after stable.v1.
37-
pytest.importorskip("dask")
38-
import dask.dataframe as dd
39-
40-
df = nw_v1.from_native(dd.from_pandas(pd.DataFrame({"a": [1, 2, 3]})))
41-
result = df.select(
42-
a=nw.col("a").cum_sum(),
43-
b=nw.col("a").cum_count(),
44-
c=nw.col("a").cum_prod(),
45-
d=nw.col("a").cum_max(),
46-
e=nw.col("a").cum_min(),
47-
f=nw.col("a").shift(1),
48-
g=nw.col("a").diff(),
49-
h=nw.col("a").is_first_distinct(),
50-
i=nw.col("a").is_last_distinct(),
51-
)
52-
expected = {
53-
"a": [1, 3, 6],
54-
"b": [1, 2, 3],
55-
"c": [1, 2, 6],
56-
"d": [1, 2, 3],
57-
"e": [1, 1, 1],
58-
"f": [None, 1.0, 2.0],
59-
"g": [None, 1.0, 1.0],
60-
"h": [True, True, True],
61-
"i": [True, True, True],
62-
}
63-
assert_equal_data(result, expected)

tests/series_only/gather_every_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
import narwhals.stable.v1 as nw_v1
5+
import narwhals as nw
66
from tests.utils import ConstructorEager, assert_equal_data
77

88
data = {"a": list(range(10))}
@@ -13,7 +13,7 @@
1313
def test_gather_every_series(
1414
constructor_eager: ConstructorEager, n: int, offset: int
1515
) -> None:
16-
series = nw_v1.from_native(constructor_eager(data), eager_only=True)["a"]
16+
series = nw.from_native(constructor_eager(data), eager_only=True)["a"]
1717

1818
result = series.gather_every(n=n, offset=offset)
1919
expected = data["a"][offset::n]

tests/series_only/head_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import pytest
44

5-
import narwhals.stable.v1 as nw_v1
5+
import narwhals as nw
66
from tests.utils import ConstructorEager, assert_equal_data
77

88

99
@pytest.mark.parametrize("n", [2, -1])
1010
def test_head_series(constructor_eager: ConstructorEager, n: int) -> None:
11-
df = nw_v1.from_native(constructor_eager({"a": [1, 2, 3]}), eager_only=True)
11+
df = nw.from_native(constructor_eager({"a": [1, 2, 3]}), eager_only=True)
1212
result = df.select(df["a"].head(n))
1313
expected = {"a": [1, 2]}
1414
assert_equal_data(result, expected)

tests/series_only/sort_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
import narwhals.stable.v1 as nw_v1
7+
import narwhals as nw
88

99
if TYPE_CHECKING:
1010
from tests.utils import ConstructorEager
@@ -24,9 +24,8 @@
2424
def test_sort_series(
2525
constructor_eager: ConstructorEager, descending: Any, nulls_last: Any, expected: Any
2626
) -> None:
27-
series = nw_v1.from_native(constructor_eager(data), eager_only=True)["b"]
27+
series = nw.from_native(constructor_eager(data), eager_only=True)["b"]
2828
result = series.sort(descending=descending, nulls_last=nulls_last)
2929
assert (
30-
result
31-
== nw_v1.from_native(constructor_eager({"a": expected}), eager_only=True)["a"]
30+
result == nw.from_native(constructor_eager({"a": expected}), eager_only=True)["a"]
3231
)

tests/series_only/tail_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import pytest
44

5-
import narwhals.stable.v1 as nw_v1
5+
import narwhals as nw
66
from tests.utils import ConstructorEager, assert_equal_data
77

88

99
@pytest.mark.parametrize("n", [2, -1])
1010
def test_tail_series(constructor_eager: ConstructorEager, n: int) -> None:
11-
df = nw_v1.from_native(constructor_eager({"a": [1, 2, 3]}), eager_only=True)
11+
df = nw.from_native(constructor_eager({"a": [1, 2, 3]}), eager_only=True)
1212
result = df.select(df["a"].tail(n))
1313
expected = {"a": [2, 3]}
1414
assert_equal_data(result, expected)

tests/translate/from_native_test.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
from contextlib import nullcontext as does_not_raise
2424
from importlib.util import find_spec
2525
from itertools import chain
26-
from typing import TYPE_CHECKING, Any, Callable, Literal, cast
26+
from typing import TYPE_CHECKING, Any, Literal, cast
2727

2828
import pytest
2929

3030
import narwhals as nw
31-
import narwhals.stable.v1 as nw_v1
3231
from narwhals._utils import Version
3332
from tests.utils import Constructor, maybe_get_modin_df
3433

@@ -409,9 +408,6 @@ def _iter_roundtrip_cases(iterable: Iterable[Any], **kwds: Any) -> Iterator[Para
409408
yield pytest.param(element, kwds, id=f"{tp.__module__}.{tp.__qualname__}")
410409

411410

412-
@pytest.mark.parametrize(
413-
"from_native", [nw.from_native, nw_v1.from_native], ids=["MAIN", "V1"]
414-
)
415411
@pytest.mark.parametrize(
416412
("native", "kwds"),
417413
list(
@@ -421,10 +417,8 @@ def _iter_roundtrip_cases(iterable: Iterable[Any], **kwds: Any) -> Iterator[Para
421417
)
422418
),
423419
)
424-
def test_from_native_roundtrip_identity(
425-
from_native: Callable[..., Any], native: Any, kwds: dict[str, Any]
426-
) -> None:
427-
nw_wrapped = from_native(native, **kwds)
420+
def test_from_native_roundtrip_identity(native: Any, kwds: dict[str, Any]) -> None:
421+
nw_wrapped = nw.from_native(native, **kwds)
428422
roundtrip = nw_wrapped.to_native()
429423
assert roundtrip is native
430424

tests/v1_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,3 +914,35 @@ def test_deprecated_expr_methods() -> None:
914914
e=(nw.col("a") == 0).arg_true(),
915915
f=nw.col("a").gather_every(2),
916916
)
917+
918+
919+
def test_dask_order_dependent_ops() -> None:
920+
# Preserve these for narwhals.stable.v1, even though they
921+
# raise after stable.v1.
922+
pytest.importorskip("dask")
923+
import dask.dataframe as dd
924+
925+
df = nw_v1.from_native(dd.from_pandas(pd.DataFrame({"a": [1, 2, 3]})))
926+
result = df.select(
927+
a=nw_v1.col("a").cum_sum(),
928+
b=nw_v1.col("a").cum_count(),
929+
c=nw_v1.col("a").cum_prod(),
930+
d=nw_v1.col("a").cum_max(),
931+
e=nw_v1.col("a").cum_min(),
932+
f=nw_v1.col("a").shift(1),
933+
g=nw_v1.col("a").diff(),
934+
h=nw_v1.col("a").is_first_distinct(),
935+
i=nw_v1.col("a").is_last_distinct(),
936+
)
937+
expected = {
938+
"a": [1, 3, 6],
939+
"b": [1, 2, 3],
940+
"c": [1, 2, 6],
941+
"d": [1, 2, 3],
942+
"e": [1, 1, 1],
943+
"f": [None, 1.0, 2.0],
944+
"g": [None, 1.0, 1.0],
945+
"h": [True, True, True],
946+
"i": [True, True, True],
947+
}
948+
assert_equal_data(result, expected)

0 commit comments

Comments
 (0)