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(rust,python,cli): add SQL engine support for SIGN function #13429

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jan 4, 2024

Adds sign support to the SQL engine (returns -1, 0, +1 depending on the sign of the argument).

Example

import polars as pl

df = pl.DataFrame({"n": [-123, None, 0, 404]})

with pl.SQLContext(data=df) as ctx:
    ctx.execute("""SELECT n, SIGN(n) AS "pos_neg" FROM data""").collect()
    
# shape: (4, 2)
# ┌──────┬─────────┐
# │ n    ┆ pos_neg │
# │ ---  ┆ ---     │
# │ i64  ┆ i64     │
# ╞══════╪═════════╡
# │ -123 ┆ -1      │
# │ null ┆ null    │
# │ 0    ┆ 0       │
# │ 404  ┆ 1       │
# └──────┴─────────┘

Misc: sorted the '# extra operations' section in the main polars Cargo.toml for clarity; likely worth doing systematically across the larger Cargo.toml blocks in all crates (currently just doing it opportunistically as I encounter them 🤔)

@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 Jan 4, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jan 4, 2024
@alexander-beedie alexander-beedie force-pushed the sql-sign-support branch 5 times, most recently from 530a01e to 5fa8b49 Compare January 4, 2024 11:44
@ritchie46 ritchie46 merged commit 054c916 into pola-rs:main Jan 4, 2024
26 checks passed
@alexander-beedie alexander-beedie deleted the sql-sign-support branch January 4, 2024 14:06
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