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,rust,cli): add SQL round support #9330

Merged
merged 4 commits into from
Jun 18, 2023

Conversation

alexander-beedie
Copy link
Collaborator

Add SQL support for ROUND function:

import polars as pl

df = pl.DataFrame( 
    {"n": [-8.499, 20.45678, 3.59901, 82.5001]} 
)
with pl.SQLContext( frame_data=df ) as ctx:
    print(
        ctx.execute("""
          SELECT 
            n,
            ROUND(n) AS n0,
            ROUND(n,1) AS n1,
            ROUND(n,2) AS n2, 
            ROUND(n,3) AS n3, 
          FROM
            frame_data
        """).collect()
    )
    
# shape: (4, 5)
# ┌──────────┬──────┬──────┬───────┬────────┐
# │ n        ┆ n0   ┆ n1   ┆ n2    ┆ n3     │
# │ ---      ┆ ---  ┆ ---  ┆ ---   ┆ ---    │
# │ f64      ┆ f64  ┆ f64  ┆ f64   ┆ f64    │
# ╞══════════╪══════╪══════╪═══════╪════════╡
# │ -8.499   ┆ -8.0 ┆ -8.5 ┆ -8.5  ┆ -8.499 │
# │ 20.45678 ┆ 20.0 ┆ 20.5 ┆ 20.46 ┆ 20.457 │
# │ 3.59901  ┆ 4.0  ┆ 3.6  ┆ 3.6   ┆ 3.599  │
# │ 82.5001  ┆ 83.0 ┆ 82.5 ┆ 82.5  ┆ 82.5   │
# └──────────┴──────┴──────┴───────┴────────┘

@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 Jun 10, 2023
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jun 10, 2023
@alexander-beedie alexander-beedie force-pushed the sql-round-function branch 2 times, most recently from 86c0a96 to 2ed9a50 Compare June 10, 2023 20:34
Copy link
Member

@ritchie46 ritchie46 left a comment

Choose a reason for hiding this comment

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

See panic comment.

@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Jun 13, 2023

See panic comment.

Yup; previous (post-comment) commit was just a rebase; will see about updating tonight.

@ritchie46
Copy link
Member

@alexander-beedie got time for this one today? Otherwise, I will finish it so that we can include it in the release today.

@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Jun 16, 2023

@alexander-beedie got time for this one today? Otherwise, I will finish it so that we can include it in the release today.

Sorry - yes, if you could handle the polars_bail (or ensure) integration that would be great; I had a brief crack at it last night but managed to dig myself into a small hole; I'll work out what patently obvious step I was missing from your diff, heh 😅

@ritchie46
Copy link
Member

Haha! Alright. :D

@ritchie46 ritchie46 enabled auto-merge (squash) June 16, 2023 09:20
@ritchie46 ritchie46 disabled auto-merge June 16, 2023 09:20
@ritchie46 ritchie46 force-pushed the sql-round-function branch from 21faa24 to 3282d88 Compare June 16, 2023 09:39
@alexander-beedie alexander-beedie enabled auto-merge (squash) June 16, 2023 13:46
@alexander-beedie alexander-beedie merged commit 05d1195 into pola-rs:main Jun 18, 2023
@alexander-beedie alexander-beedie deleted the sql-round-function branch June 18, 2023 06:57
c-peters pushed a commit to c-peters/polars that referenced this pull request Jul 14, 2023
Co-authored-by: ritchie <ritchie46@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql Area: Polars SQL functionality 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.

2 participants