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

fix: String transform to_titlecase was too narrowly defined #18122

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Aug 9, 2024

Closes #18116.

Note, closes the issue by better-aligning to_titlecase to the standard implementation, not by adding new options. (We were defining "word" boundaries by whitespace, but that is a much narrower definition than normal, which considers all non-alphanumeric chars as boundaries; updated the docstrings with a note to explain what constitutes a word boundary).

Example

import polars.selectors as cs
import polars as pl

df = pl.DataFrame({
    "quotes": [
        "'e.t. phone home'",
        "i feel the need--the need for speed",
        "to infinity,and BEYOND!",
        "say 'what' again!i dare you - I\u00a0double-dare you!",
        "What.we.got.here... is#failure#to#communicate",
    ]
})

with pl.Config(fmt_str_lengths=50):
    print(
        df.select(cs.string().str.to_titlecase())
    )

Before

# shape: (5, 1)
# ┌──────────────────────────────────────────────────┐
# │ quotes                                           │
# │ ---                                              │
# │ str                                              │
# ╞══════════════════════════════════════════════════╡
# │ 'e.t. Phone Home'                                │
# │ I Feel The Need--the Need For Speed              │
# │ To Infinity,and Beyond!                          │
# │ Say 'what' Again!i Dare You - I Double-dare You! │
# │ What.we.got.here... Is#failure#to#communicate    │
# └──────────────────────────────────────────────────┘

After

# shape: (5, 1)
# ┌──────────────────────────────────────────────────┐
# │ quotes                                           │
# │ ---                                              │
# │ str                                              │
# ╞══════════════════════════════════════════════════╡
# │ 'E.T. Phone Home'                                │
# │ I Feel The Need--The Need For Speed              │
# │ To Infinity,And Beyond!                          │
# │ Say 'What' Again!I Dare You - I Double-Dare You! │
# │ What.We.Got.Here... Is#Failure#To#Communicate    │
# └──────────────────────────────────────────────────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Aug 9, 2024
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.34%. Comparing base (9dd9569) to head (1136500).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18122      +/-   ##
==========================================
+ Coverage   80.33%   80.34%   +0.01%     
==========================================
  Files        1496     1496              
  Lines      197685   197685              
  Branches     2821     2821              
==========================================
+ Hits       158806   158831      +25     
+ Misses      38358    38333      -25     
  Partials      521      521              

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

@ritchie46
Copy link
Member

Seems more robust indeed.

@ritchie46 ritchie46 merged commit bc65bd0 into pola-rs:main Aug 10, 2024
27 checks passed
@alexander-beedie alexander-beedie deleted the fix-titlecase branch August 10, 2024 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

str.to_titlecase() add option for capital after hyphen
2 participants