Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/dataframe/test_window.py
8405 views
1
import polars as pl
2
from polars.testing import assert_frame_equal
3
4
5
def test_single_row_literal_ambiguity_8481() -> None:
6
df = pl.DataFrame(
7
{
8
"store_id": [1],
9
"cost_price": [2.0],
10
}
11
)
12
13
inverse_cost_price = 1.0 / pl.col("cost_price")
14
result = df.with_columns(
15
(inverse_cost_price / inverse_cost_price.sum()).over("store_id").alias("result")
16
)
17
# exceptions.ComputeError: cannot aggregate a literal
18
19
expected = pl.DataFrame(
20
{
21
"store_id": [1],
22
"cost_price": [2.0],
23
"result": [1.0],
24
}
25
)
26
assert_frame_equal(result, expected)
27
28