Skip to content

Commit 51925d6

Browse files
committed
test: Identify horizontal/elementwise gap?
Seems like allowing elementwise *only* here was unintentional? Also a note on head/tail/slice
1 parent 0fa48a0 commit 51925d6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/plan/expr_parsing_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ def test_function_expr_horizontal(
8282
assert sequence_node != unrelated_node
8383

8484

85+
def test_valid_windows() -> None:
86+
"""Was planning to test this matched, but we seem to allow elementwise horizontal?
87+
88+
https://github.com/narwhals-dev/narwhals/blob/63c8e4771a1df4e0bfeea5559c303a4a447d5cc2/tests/expression_parsing_test.py#L10-L45
89+
"""
90+
ELEMENTWISE_ERR = re.compile(r"cannot use.+over.+elementwise", re.IGNORECASE) # noqa: N806
91+
a = nwd.col("a")
92+
assert a.cum_sum()
93+
assert a.cum_sum().over(order_by="id")
94+
with pytest.raises(InvalidOperationError, match=ELEMENTWISE_ERR):
95+
assert a.cum_sum().abs().over(order_by="id")
96+
97+
assert (a.cum_sum() + 1).over(order_by="id")
98+
assert a.cum_sum().cum_sum().over(order_by="id")
99+
assert a.cum_sum().cum_sum()
100+
assert nwd.sum_horizontal(a, a.cum_sum())
101+
with pytest.raises(InvalidOperationError, match=ELEMENTWISE_ERR):
102+
assert nwd.sum_horizontal(a, a.cum_sum()).over(order_by="a")
103+
104+
assert nwd.sum_horizontal(a, a.cum_sum().over(order_by="i"))
105+
assert nwd.sum_horizontal(a.diff(), a.cum_sum().over(order_by="i"))
106+
with pytest.raises(InvalidOperationError, match=ELEMENTWISE_ERR):
107+
assert nwd.sum_horizontal(a.diff(), a.cum_sum()).over(order_by="i")
108+
109+
with pytest.raises(InvalidOperationError, match=ELEMENTWISE_ERR):
110+
assert nwd.sum_horizontal(a.diff().abs(), a.cum_sum()).over(order_by="i")
111+
112+
85113
# TODO @dangotbanned: Get parity with the existing tests
86114
# https://github.com/narwhals-dev/narwhals/blob/63c8e4771a1df4e0bfeea5559c303a4a447d5cc2/tests/expression_parsing_test.py#L48-L105
87115

@@ -110,6 +138,9 @@ def test_filter_aggregation() -> None:
110138

111139

112140
# TODO @dangotbanned: Add `head`, `tail`
141+
# head/tail are implemented in terms of `Expr::Slice`
142+
# We don't support `Expr.slice`, seems odd to add it for a deprecation 🤔
143+
# polars allows this in `select`, but not `with_columns`
113144
def test_head_aggregation() -> None:
114145
with pytest.raises(InvalidOperationError):
115146
nwd.col("a").mean().head() # type: ignore[attr-defined]

0 commit comments

Comments
 (0)