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: Add an is_literal method to expression meta namespace #19773

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

alexander-beedie
Copy link
Collaborator

Added a simple is_literal extension to the "meta" namespace.

(There's a slight subtlety when matching datetime literals, as an implicit strict-cast gets injected; otherwise it's just simple matching).

Examples

from datetime import datetime
import polars as pl

for value in (123, "four five", datetime.now()):
    e = pl.lit(value)
    e.meta.is_literal()
    # True
    
    e = pl.lit(value).alias("foo")
    e.meta.is_literal()
    # False
    
    e = pl.lit(value).alias("foo")
    e.meta.is_literal(allow_aliasing=True)
    # True

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Nov 14, 2024
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.56%. Comparing base (8cb7839) to head (e4246d3).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #19773   +/-   ##
=======================================
  Coverage   79.55%   79.56%           
=======================================
  Files        1544     1544           
  Lines      213240   213253   +13     
  Branches     2441     2441           
=======================================
+ Hits       169643   169665   +22     
+ Misses      43048    43039    -9     
  Partials      549      549           

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

Copy link
Contributor

@etiennebacher etiennebacher left a comment

Choose a reason for hiding this comment

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

This should be listed in meta.rst as well? (Just noticing because of #19744)

@alexander-beedie
Copy link
Collaborator Author

This should be listed in meta.rst as well? (Just noticing because of #19744)

It certainly should - thx for the reminder (fixed) 😉

@alexander-beedie alexander-beedie merged commit 85b8de2 into pola-rs:main Nov 14, 2024
26 checks passed
@alexander-beedie alexander-beedie deleted the expr-meta-is-literal branch November 14, 2024 13:00
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 rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants