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 INITCAP string function for SQL #9884

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jul 14, 2023

Adds support for the SQL equivalent of to_titlecase (to which this maps).

Example

import polars as pl
df = pl.DataFrame( { "words": ["Test SOME words"] } )

with pl.SQLContext( frame=df ) as ctx:
    res = ctx.execute(
        """
        SELECT
          words,
          INITCAP(words) as cap,
          UPPER(words) as upper,
          LOWER(words) as lower,
        FROM frame
        """
    ).collect()
    
# shape: (1, 4)
# ┌─────────────────┬─────────────────┬─────────────────┬─────────────────┐
# │ words           ┆ cap             ┆ upper           ┆ lower           │
# │ ---             ┆ ---             ┆ ---             ┆ ---             │
# │ str             ┆ str             ┆ str             ┆ str             │
# ╞═════════════════╪═════════════════╪═════════════════╪═════════════════╡
# │ Test SOME words ┆ Test Some Words ┆ TEST SOME WORDS ┆ test some words │
# └─────────────────┴─────────────────┴─────────────────┴─────────────────┘

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Jul 14, 2023
@universalmind303
Copy link
Collaborator

universalmind303 commented Jul 14, 2023

since INITCAP is Oracle specific, I'm wondering if we just want to call it TITLECASE instead?

@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jul 14, 2023
@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Jul 14, 2023

since INITCAP is Oracle specific, I'm wondering if we just want to call it TITLECASE instead?

No need - it's native PostgreSQL too (something I learned today, lol...) ;)
https://www.postgresql.org/docs/15/functions-string.html

@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Oct 4, 2023

Oops; left this for a while 😅
Updated/rebased against the latest code and all seems green.

@ritchie46 ritchie46 merged commit b657f8d into pola-rs:main Oct 4, 2023
24 checks passed
@alexander-beedie alexander-beedie deleted the sql-string-initcap branch October 5, 2023 06:42
@alexander-beedie alexander-beedie changed the title feat(python): add INITCAP string function for SQL feat(python, rust,cli): add INITCAP string function for SQL Oct 5, 2023
@alexander-beedie alexander-beedie changed the title feat(python, rust,cli): add INITCAP string function for SQL feat(python,rust,cli): add INITCAP string function for SQL Oct 5, 2023
@github-actions github-actions bot added the rust Related to Rust Polars label Oct 5, 2023
orlp pushed a commit to orlp/polars that referenced this pull request Oct 5, 2023
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.

3 participants