Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support cumulative aggregations for Decimal dtype #20802

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

lukemanley
Copy link
Contributor

@lukemanley lukemanley commented Jan 20, 2025

Fixes #14745

import polars as pl
from decimal import Decimal as D

df = pl.Series("a", ["2.2", "1.1", "3.3"], pl.Decimal(21, 1)).to_frame()

df.select(
    pl.col("a").cum_sum().alias("cumulative_sum"),
    pl.col("a").cum_min().alias("cumulative_min"),
    pl.col("a").cum_max().alias("cumulative_max"),
)

BEFORE: (cum_sum raised InvalidOperationError):

┌────────────────┬────────────────┐
│ cumulative_min ┆ cumulative_max │
│ ---            ┆ ---            │
│ decimal[21,1]  ┆ decimal[21,1]  │
╞════════════════╪════════════════╡
│ 22.0           ┆ 22.0           │
│ 11.0           ┆ 22.0           │
│ 11.0           ┆ 33.0           │
└────────────────┴────────────────┘

AFTER:

┌────────────────┬────────────────┬────────────────┐
│ cumulative_sum ┆ cumulative_min ┆ cumulative_max │
│ ---            ┆ ---            ┆ ---            │
│ decimal[21,1]  ┆ decimal[21,1]  ┆ decimal[21,1]  │
╞════════════════╪════════════════╪════════════════╡
│ 2.2            ┆ 2.2            ┆ 2.2            │
│ 3.3            ┆ 1.1            ┆ 2.2            │
│ 6.6            ┆ 1.1            ┆ 3.3            │
└────────────────┴────────────────┴────────────────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jan 20, 2025
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.78%. Comparing base (f0aa09b) to head (f9705e8).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #20802   +/-   ##
=======================================
  Coverage   79.77%   79.78%           
=======================================
  Files        1561     1561           
  Lines      222029   222044   +15     
  Branches     2533     2533           
=======================================
+ Hits       177132   177152   +20     
+ Misses      44313    44308    -5     
  Partials      584      584           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46 ritchie46 changed the title fix: Fix cumulative aggregations for Decimal dtype feat: Support cumulative aggregations for Decimal dtype Jan 20, 2025
@ritchie46
Copy link
Member

Nice one!

@github-actions github-actions bot added the enhancement New feature or an improvement of an existing feature label Jan 20, 2025
@ritchie46 ritchie46 merged commit 374bce7 into pola-rs:main Jan 20, 2025
30 checks passed
@lukemanley lukemanley deleted the fix-decimal-cumulative-aggs branch January 23, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cum_sum operation not supported for decimals
2 participants