Skip to content

Commit 8770d37

Browse files
authored
Merge branch 'main' into from-numpy-2d-ns
2 parents dabe5d4 + 9da549e commit 8770d37

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

narwhals/dataframe.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,11 +2174,10 @@ def _extract_compliant(self: Self, arg: Any) -> Any:
21742174
msg = (
21752175
"Order-dependent expressions are not supported for use in LazyFrame.\n\n"
21762176
"Hints:\n"
2177-
"- Instead of `lf.select(nw.col('a').sort())`, use `lf.select('a').sort()\n"
2178-
"- Instead of `lf.select(nw.col('a').head())`, use `lf.select('a').head()\n"
2179-
"- `Expr.cum_sum`, and other such expressions, are not currently supported.\n"
2180-
" In a future version of Narwhals, a `order_by` argument will be added to\n"
2181-
" `over` and they will be supported."
2177+
"- Instead of `lf.select(nw.col('a').sort())`, use `lf.select('a').sort()`.\n"
2178+
"- Instead of `lf.select(nw.col('a').cum_sum())`, use\n"
2179+
" `lf.select(nw.col('a').cum_sum().over(order_by='date'))`.\n\n"
2180+
"See https://narwhals-dev.github.io/narwhals/basics/order_dependence/."
21822181
)
21832182
raise OrderDependentExprError(msg)
21842183
if arg._metadata.kind.is_filtration():

tests/expr_and_series/arithmetic_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import narwhals.stable.v1 as nw
1111
from tests.utils import DASK_VERSION
12+
from tests.utils import DUCKDB_VERSION
1213
from tests.utils import PANDAS_VERSION
1314
from tests.utils import Constructor
1415
from tests.utils import ConstructorEager
@@ -341,7 +342,9 @@ def test_arithmetic_series_left_literal(
341342

342343

343344
def test_std_broadcating(constructor: Constructor) -> None:
344-
# `std(ddof=2)` fails for duckdb here
345+
if "duckdb" in str(constructor) and DUCKDB_VERSION < (1, 3):
346+
# `std(ddof=2)` fails for duckdb here
347+
pytest.skip()
345348
df = nw.from_native(constructor({"a": [1, 2, 3]}))
346349
result = df.with_columns(b=nw.col("a").std()).sort("a")
347350
expected = {"a": [1, 2, 3], "b": [1.0, 1.0, 1.0]}

tests/expr_and_series/over_test.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,29 @@ def test_over_single(constructor: Constructor) -> None:
4040
"a": ["a", "a", "b", "b", "b"],
4141
"b": [1, 2, 3, 5, 3],
4242
"c": [5, 4, 3, 2, 1],
43+
"i": list(range(5)),
4344
"c_max": [5, 5, 3, 3, 3],
4445
}
4546

46-
result = df.with_columns(c_max=nw.col("c").max().over("a")).sort("i").drop("i")
47+
result = df.with_columns(c_max=nw.col("c").max().over("a")).sort("i")
4748
assert_equal_data(result, expected)
48-
result = df.with_columns(c_max=nw.col("c").max().over(["a"])).sort("i").drop("i")
49+
result = df.with_columns(c_max=nw.col("c").max().over(["a"])).sort("i")
4950
assert_equal_data(result, expected)
5051

5152

5253
def test_over_std_var(request: pytest.FixtureRequest, constructor: Constructor) -> None:
5354
if "cudf" in str(constructor):
5455
# https://github.com/rapidsai/cudf/issues/18159
5556
request.applymarker(pytest.mark.xfail)
57+
if "duckdb" in str(constructor) and DUCKDB_VERSION < (1, 3):
58+
pytest.skip()
5659

5760
df = nw.from_native(constructor(data))
5861
expected = {
5962
"a": ["a", "a", "b", "b", "b"],
6063
"b": [1, 2, 3, 5, 3],
6164
"c": [5, 4, 3, 2, 1],
65+
"i": list(range(5)),
6266
"c_std0": [0.5, 0.5, 0.816496580927726, 0.816496580927726, 0.816496580927726],
6367
"c_std1": [0.7071067811865476, 0.7071067811865476, 1.0, 1.0, 1.0],
6468
"c_var0": [
@@ -71,16 +75,12 @@ def test_over_std_var(request: pytest.FixtureRequest, constructor: Constructor)
7175
"c_var1": [0.5, 0.5, 1.0, 1.0, 1.0],
7276
}
7377

74-
result = (
75-
df.with_columns(
76-
c_std0=nw.col("c").std(ddof=0).over("a"),
77-
c_std1=nw.col("c").std(ddof=1).over("a"),
78-
c_var0=nw.col("c").var(ddof=0).over("a"),
79-
c_var1=nw.col("c").var(ddof=1).over("a"),
80-
)
81-
.sort("i")
82-
.drop("i")
83-
)
78+
result = df.with_columns(
79+
c_std0=nw.col("c").std(ddof=0).over("a"),
80+
c_std1=nw.col("c").std(ddof=1).over("a"),
81+
c_var0=nw.col("c").var(ddof=0).over("a"),
82+
c_var1=nw.col("c").var(ddof=1).over("a"),
83+
).sort("i")
8484
assert_equal_data(result, expected)
8585

8686

@@ -92,6 +92,7 @@ def test_over_multiple(constructor: Constructor) -> None:
9292
"a": ["a", "a", "b", "b", "b"],
9393
"b": [1, 2, 3, 3, 5],
9494
"c": [5, 4, 3, 1, 2],
95+
"i": list(range(5)),
9596
"c_min": [5, 4, 1, 1, 2],
9697
}
9798
expected = {
@@ -100,7 +101,7 @@ def test_over_multiple(constructor: Constructor) -> None:
100101
"c": [5, 4, 3, 2, 1],
101102
}
102103

103-
result = df.with_columns(c_min=nw.col("c").min().over("a", "b")).sort("i").drop("i")
104+
result = df.with_columns(c_min=nw.col("c").min().over("a", "b")).sort("i")
104105
assert_equal_data(result, expected)
105106

106107

tests/frame/add_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
from __future__ import annotations
22

3+
import pytest
4+
35
import narwhals.stable.v1 as nw
6+
from tests.utils import DUCKDB_VERSION
47
from tests.utils import Constructor
58
from tests.utils import assert_equal_data
69

710

811
def test_add(constructor: Constructor) -> None:
12+
if "duckdb" in str(constructor) and DUCKDB_VERSION < (1, 3):
13+
pytest.skip()
914
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8.0, 9.0]}
1015
df = nw.from_native(constructor(data))
1116
result = df.with_columns(

0 commit comments

Comments
 (0)