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] Add str.capitalize() function #2003

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

murex971
Copy link
Contributor

Uppercase the first letter, lowercase the rest.

Resolves #1919

@murex971 murex971 force-pushed the murex/capitalize-str branch 2 times, most recently from 48234aa to 4fc08bb Compare March 12, 2024 14:21
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.27%. Comparing base (093e8d7) to head (226b3ee).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2003      +/-   ##
==========================================
- Coverage   84.70%   84.27%   -0.44%     
==========================================
  Files          58       59       +1     
  Lines        6363     6409      +46     
==========================================
+ Hits         5390     5401      +11     
- Misses        973     1008      +35     
Files Coverage Δ
daft/expressions/expressions.py 91.64% <100.00%> (+0.15%) ⬆️
daft/series.py 93.19% <100.00%> (+0.04%) ⬆️

... and 2 files with indirect coverage changes

@samster25 samster25 added the enhancement New feature or request label Mar 12, 2024
Copy link
Contributor

@jaychia jaychia left a comment

Choose a reason for hiding this comment

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

Thanks! This looks pretty clean. 🚀 🚀 🚀

Just a few comments and we should be good

Some(first) => {
let firstchar = first.to_uppercase();
let mut res = String::with_capacity(v.len());
res.extend(firstchar);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: it seems that firstchar may actually not be a single character in certain special cases, based on https://doc.rust-lang.org/std/primitive.char.html#method.to_uppercase

Let's rename the firstchar variable to first_char_uppercased?

let firstchar = first.to_uppercase();
let mut res = String::with_capacity(v.len());
res.extend(firstchar);
for c in chars {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: prefer iterator chaining if possible

res.extend(chars.flat_map(|c| c.to_lowercase()))

@murex971
Copy link
Contributor Author

@jaychia thanks for the review. Pushed the changes.

@jaychia jaychia merged commit 492973a into Eventual-Inc:main Mar 13, 2024
27 checks passed
@jaychia
Copy link
Contributor

jaychia commented Mar 13, 2024

Congrats on first PR!!! 🚀🚀🚀

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.

[EXPRESSIONS] .str.capitalize()
3 participants