Skip to content

Rolling functions allow specifying negative weights #29249

Description

@dsprenkels

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

s = pl.Series("a", [1.0, 2.0, 3.0, 4.0])

weights = [5.0, 1.0, -1.0]
print(result := s.rolling_median(window_size=3, min_samples=1, weights=weights))

Log output

running script: python3 "/home/amber/git/scratch/test-rolling-weighted-quantile-zero-wsum.py" 
shape: (4,)
Series: 'a' [f64]
[
        NaN # !!
        0.5
        1.0
        2.0
]

Issue description

Polars will happily compute rolling_ operations with negative weights, even though this is 100% undefined. It should—however—raise an error instead.

Expected behavior

Raise an InvalidOperationError

Installed versions

Details
Polars:              2.0.0-rc.1
Build:               <unknown>
Index type:          UInt32
Platform:            Linux-7.2.3-1-cachyos-x86_64-with-glibc2.44
Python:              3.14.7 (main, Aug 13 2026, 07:40:04) [GCC 16.2.1 20260810]
Runtime:             rt32

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  1.12.0
altair               6.2.2
azure.identity       1.25.3
boto3                1.43.56
cloudpickle          3.1.2
connectorx           0.4.5
deltalake            1.6.2
fastexcel            0.21.0
fsspec               2026.7.0
gevent               26.8.0
google.auth          2.56.3
great_tables         0.23.0
matplotlib           3.11.1
numpy                2.5.2
openpyxl             3.1.5
pandas               3.0.5
polars_cloud         0.10.0
pyarrow              25.0.1
pydantic             2.13.4
pyiceberg            0.11.1
sqlalchemy           2.0.52
torch                <not installed>
xlsx2csv             0.8.6
xlsxwriter           3.2.9

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P-lowPriority: lowacceptedReady for implementationbugSomething isn't workingpythonRelated to Python Polars

Type

No type

Projects

  • Status
    Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions