Skip to content

cum_sum with lit gives random incorrect results #26800

@xbr32

Description

@xbr32

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

print(
    pl.DataFrame({
        "group": ["a", "a", "a", "b", "b", "a"]
    })
    .with_columns(pl.lit(1).cum_sum().over("group").alias("cum_sum"))
)

Log output

shape: (6, 2)
┌───────┬─────────┐
│ group ┆ cum_sum │
│ ---   ┆ ---     │
│ str   ┆ i32     │
╞═══════╪═════════╡
│ a     ┆ 1       │
│ a     ┆ 0       │
│ a     ┆ 1       │
│ b     ┆ 0       │
│ b     ┆ 2       │
│ a     ┆ 0       │
└───────┴─────────┘

Issue description

The results are wrong and are random. I get different values if I try on another computer.
Correct results are below in "expected behavior".

Expected behavior

shape: (6, 2)

group cum_sum
str i32
"a" 1
"a" 2
"a" 3
"b" 1
"b" 2
"a" 4

Installed versions

Details
--------Version info---------
Polars:              1.38.1
Index type:          UInt32
Platform:            Linux-6.18.8-1.surface.fc43.x86_64-x86_64-with-glibc2.42
Python:              3.13.11 (main, Nov 10 2011, 15:00:00) [GCC 15.2.0]
Runtime:             rt32

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           <not installed>
numpy                <not installed>
openpyxl             <not installed>
pandas               <not installed>
polars_cloud         <not installed>
pyarrow              <not installed>
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>

Metadata

Metadata

Assignees

Labels

P-highPriority: highacceptedReady for implementationbugSomething isn't workingpythonRelated to Python Polars

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions