Skip to content

feat: Add str.pad_{start,end}#3395

Merged
FBruzzesi merged 14 commits intonarwhals-dev:mainfrom
camriddell:feat/str-pad
Jan 13, 2026
Merged

feat: Add str.pad_{start,end}#3395
FBruzzesi merged 14 commits intonarwhals-dev:mainfrom
camriddell:feat/str-pad

Conversation

@camriddell
Copy link
Copy Markdown
Member

Description

Adds str.pad_start and str.pad_end to pad strings within a column.

import narwhals as nw
import pandas as pd
df_native = pd.DataFrame({"a": ["cow", "monkey", "hippopotamus", None]})
df = nw.from_native(df_native)
print(
    df.with_columns(
        pad_start=nw.col("a").str.pad_start(8, "*"),
        pad_end=nw.col("a").str.pad_end(8, "*"),
    )
)
# ┌───────────────────────────────────────────┐
# |            Narwhals DataFrame             |
# |-------------------------------------------|
# |              a     pad_start       pad_end|
# |0           cow      *****cow      cow*****|
# |1        monkey      **monkey      monkey**|
# |2  hippopotamus  hippopotamus  hippopotamus|
# |3          None          None          None|
# └───────────────────────────────────────────┘

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

Copy link
Copy Markdown
Member

@FBruzzesi FBruzzesi left a comment

Choose a reason for hiding this comment

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

Thanks @camriddell , just a couple of minor details to take care of

camriddell and others added 3 commits January 9, 2026 14:36
Co-authored-by: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com>
Co-authored-by: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com>
Co-authored-by: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com>
@dangotbanned dangotbanned added the enhancement New feature or request label Jan 9, 2026
Copy link
Copy Markdown
Member

@dangotbanned dangotbanned left a comment

Choose a reason for hiding this comment

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

Looking good @camriddell!

Only suggestion from me is to try stealing some test cases from polars and see if everything is still happy

The unicode tests look funky (pola-rs/polars#12008)

@camriddell
Copy link
Copy Markdown
Member Author

Looking good @camriddell!

Only suggestion from me is to try stealing some test cases from polars and see if everything is still happy

The unicode tests look funky (pola-rs/polars#12008)

Yeah, fingers crossed that these are handled somewhat consistently/supported across backends. I'll pull these tests over and see where we land!

@camriddell
Copy link
Copy Markdown
Member Author

@dangotbanned those unicode tests fit into place without any poking from me :)

Copy link
Copy Markdown
Member

@dangotbanned dangotbanned left a comment

Choose a reason for hiding this comment

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

@dangotbanned those unicode tests fit into place without any poking from me :)

Happy to hear it, thanks @camriddell!

I'm jealous of how small this PR is 😉

spinny hands narwhal

@dangotbanned dangotbanned changed the title feat: String pad_start & pad_end feat: Add str.pad_{start,end} Jan 12, 2026
@FBruzzesi FBruzzesi merged commit 55c2b0d into narwhals-dev:main Jan 13, 2026
33 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enh]: Add str.pad_start, str.pad_end

3 participants