11from __future__ import annotations
22
3+ import re
34from typing import TYPE_CHECKING , Callable , Iterable
45
56import pytest
@@ -81,17 +82,10 @@ def test_function_expr_horizontal(
8182 assert sequence_node != unrelated_node
8283
8384
84- # TODO @dangotbanned: Get partity with the existing tests
85+ # TODO @dangotbanned: Get parity with the existing tests
8586# https://github.com/narwhals-dev/narwhals/blob/63c8e4771a1df4e0bfeea5559c303a4a447d5cc2/tests/expression_parsing_test.py#L48-L105
8687
8788
88- def test_misleading_order_by () -> None :
89- with pytest .raises (InvalidOperationError ):
90- nw .col ("a" ).mean ().over (order_by = "b" )
91- with pytest .raises (InvalidOperationError ):
92- nw .col ("a" ).rank ().over (order_by = "b" )
93-
94-
9589# `test_double_over` is already covered in the later `test_nested_over`
9690
9791
@@ -107,6 +101,9 @@ def test_invalid_repeat_agg() -> None:
107101 nwd .col ("a" ).all ().quantile (0.5 , "linear" )
108102
109103
104+ # TODO @dangotbanned: Weirdly, `polars` suggestion **does** resolve it
105+ # InvalidOperationError: Series idx, length 1 doesn't match the DataFrame height of 9
106+ # If you want expression: col("idx").mean().drop_nulls() to be broadcasted, ensure it is a scalar (for instance by adding '.first()')
110107def test_filter_aggregation () -> None :
111108 with pytest .raises (InvalidOperationError ):
112109 nwd .col ("a" ).mean ().drop_nulls ()
@@ -118,32 +115,48 @@ def test_head_aggregation() -> None:
118115 nwd .col ("a" ).mean ().head () # type: ignore[attr-defined]
119116
120117
118+ # TODO @dangotbanned: (Same as `test_filter_aggregation`)
121119def test_rank_aggregation () -> None :
122120 with pytest .raises (InvalidOperationError ):
123121 nwd .col ("a" ).mean ().rank ()
124122
125123
124+ # TODO @dangotbanned: No error in `polars`, but results in all `null`s
126125def test_diff_aggregation () -> None :
127126 with pytest .raises (InvalidOperationError ):
128127 nwd .col ("a" ).mean ().diff ()
129128
130129
131- def test_invalid_over () -> None :
130+ # TODO @dangotbanned: Non-`polars`` rule
131+ def test_misleading_order_by () -> None :
132+ with pytest .raises (InvalidOperationError ):
133+ nwd .col ("a" ).mean ().over (order_by = "b" )
132134 with pytest .raises (InvalidOperationError ):
135+ nwd .col ("a" ).rank ().over (order_by = "b" )
136+
137+
138+ # NOTE: Non-`polars`` rule
139+ def test_invalid_over () -> None :
140+ pattern = re .compile (r"cannot use.+over.+elementwise" , re .IGNORECASE )
141+ with pytest .raises (InvalidOperationError , match = pattern ):
133142 nwd .col ("a" ).fill_null (3 ).over ("b" )
134143
135144
136145def test_nested_over () -> None :
137- with pytest .raises (InvalidOperationError ):
146+ pattern = re .compile (r"cannot nest.+over" , re .IGNORECASE )
147+ with pytest .raises (InvalidOperationError , match = pattern ):
138148 nwd .col ("a" ).mean ().over ("b" ).over ("c" )
139- with pytest .raises (InvalidOperationError ):
149+ with pytest .raises (InvalidOperationError , match = pattern ):
140150 nwd .col ("a" ).mean ().over ("b" ).over ("c" , order_by = "i" )
141151
142152
153+ # NOTE: This *can* error in polars, but only if the length **actualy changes**
154+ # The rule then breaks down to needing the same length arrays in all parts of the over
143155def test_filtration_over () -> None :
144- with pytest .raises (InvalidOperationError ):
156+ pattern = re .compile (r"cannot use.+over.+change length" , re .IGNORECASE )
157+ with pytest .raises (InvalidOperationError , match = pattern ):
145158 nwd .col ("a" ).drop_nulls ().over ("b" )
146- with pytest .raises (InvalidOperationError ):
159+ with pytest .raises (InvalidOperationError , match = pattern ):
147160 nwd .col ("a" ).drop_nulls ().over ("b" , order_by = "i" )
148- with pytest .raises (InvalidOperationError ):
161+ with pytest .raises (InvalidOperationError , match = pattern ):
149162 nwd .col ("a" ).diff ().drop_nulls ().over ("b" , order_by = "i" )
0 commit comments