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(python): Support Decimal inputs for lit #16950

Merged
merged 1 commit into from
Jun 14, 2024
Merged

feat(python): Support Decimal inputs for lit #16950

merged 1 commit into from
Jun 14, 2024

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented Jun 14, 2024

Closes #13341

Previously, passing Python Decimal objects to lit was unsupported. Now it works:

from decimal import Decimal
import polars as pl

expr = pl.lit(Decimal("0.1"))
print(pl.select(expr))
shape: (1, 1)
┌──────────────┐
│ literal      │
│ ---          │
│ decimal[*,1] │
╞══════════════╡
│ 0.1          │
└──────────────┘

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Jun 14, 2024
@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Jun 14, 2024

Closes #13341 👍

Comment on lines +432 to +434
} else if value.get_type().qualname().unwrap() == "Decimal" {
let av = py_object_to_any_value(value, true)?;
Ok(Expr::Literal(LiteralValue::try_from(av).unwrap()).into())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing logic for lit should be unified with that of AnyValue. For now, this works...

Copy link

codspeed-hq bot commented Jun 14, 2024

CodSpeed Performance Report

Merging #16950 will improve performances by 27.51%

Comparing lit-decimal (ce6838d) with main (d8e4a61)

Summary

⚡ 1 improvements
✅ 36 untouched benchmarks

Benchmarks breakdown

Benchmark main lit-decimal Change
test_groupby_h2oai_q7 2.6 ms 2 ms +27.51%

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.98%. Comparing base (d8e4a61) to head (ce6838d).

Files Patch % Lines
crates/polars-plan/src/logical_plan/lit.rs 66.66% 1 Missing ⚠️
py-polars/src/lazyframe/visitor/expr_nodes.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16950      +/-   ##
==========================================
+ Coverage   80.96%   80.98%   +0.01%     
==========================================
  Files        1445     1445              
  Lines      189916   189925       +9     
  Branches     2712     2712              
==========================================
+ Hits       153771   153803      +32     
+ Misses      35645    35623      -22     
+ Partials      500      499       -1     

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

@ritchie46 ritchie46 merged commit 7ebcfab into main Jun 14, 2024
28 checks passed
@ritchie46 ritchie46 deleted the lit-decimal branch June 14, 2024 09:44
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
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 python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot instantiate pl.lit with a Decimal value
3 participants