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

refactor(rust): Unify internal string type #18425

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Aug 28, 2024

Column names, various field names, DSL / IR fields, timezone strings, etc.

Notes:

  • I've changed function signatures with the following intent:
    • arg: PlSmallStr - this is our owned string type, which we pass to functions that internally do things like e.g. ca.with_name(arg).
      • This is except for the functions in our Rust DSL - as otherwise they would be very hard to use.
    • arg: &PlSmallStr - micro-optimization for functions that don't always clone, this is very rare - usually &str is used instead
    • arg: &str - the usual rust function that doesn't need owned strings, call-sites to these functions that have s: PlSmallStrs will often use s.as_str().

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PlSmallStr(CompactString);

impl PlSmallStr {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@orlp here

crates/polars-utils/src/pl_str.rs Outdated Show resolved Hide resolved
}
}

impl AsRef<str> for PlSmallStr {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add AsRef<Path> and AsRef<[u8]>?

crates/polars-utils/src/pl_str.rs Outdated Show resolved Hide resolved
crates/polars-utils/src/pl_str.rs Outdated Show resolved Hide resolved
}
}

impl From<String> for PlSmallStr {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also add FromIterator<T> for at least char, String and &'a str?

crates/polars-utils/src/pl_str.rs Outdated Show resolved Hide resolved
@nameexhaustion nameexhaustion changed the title wip: Unify string type refactor(rust): Unify string type Aug 29, 2024
@github-actions github-actions bot added internal An internal refactor or improvement rust Related to Rust Polars and removed title needs formatting labels Aug 29, 2024
with_columns = Some(Arc::from(columns));
Some(name.clone())
})
.collect::<Arc<[_]>>(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

drive-by refactored

@nameexhaustion nameexhaustion changed the title refactor(rust): Unify string type refactor(rust): Unify internal string type Aug 29, 2024
Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 84.78865% with 493 lines in your changes missing coverage. Please review.

Project coverage is 79.84%. Comparing base (b2550a0) to head (5ef6836).
Report is 38 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-core/src/frame/group_by/mod.rs 67.03% 30 Missing ⚠️
crates/polars-core/src/frame/mod.rs 81.41% 29 Missing ⚠️
crates/polars-arrow/src/datatypes/field.rs 9.52% 19 Missing ⚠️
crates/polars-core/src/frame/row/av_buffer.rs 88.81% 18 Missing ⚠️
crates/polars-arrow/src/io/avro/read/schema.rs 10.52% 17 Missing ⚠️
crates/polars-json/src/json/infer_schema.rs 27.27% 16 Missing ⚠️
crates/polars-expr/src/expressions/aggregation.rs 80.00% 14 Missing ⚠️
crates/polars-arrow/src/io/ipc/write/schema.rs 27.77% 13 Missing ⚠️
...ates/polars-core/src/chunked_array/iterator/mod.rs 75.92% 13 Missing ⚠️
crates/polars-core/src/serde/mod.rs 40.00% 12 Missing ⚠️
... and 97 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18425      +/-   ##
==========================================
- Coverage   79.86%   79.84%   -0.02%     
==========================================
  Files        1496     1497       +1     
  Lines      200364   201825    +1461     
  Branches     2867     2867              
==========================================
+ Hits       160012   161155    +1143     
- Misses      39806    40124     +318     
  Partials      546      546              

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

@nameexhaustion
Copy link
Collaborator Author

Will address remaining review points in follow-up PRs

@ritchie46 ritchie46 merged commit 4aa619d into pola-rs:main Aug 29, 2024
22 checks passed
@nameexhaustion nameexhaustion deleted the pl-str branch August 29, 2024 09:58
r-brink pushed a commit to r-brink/polars that referenced this pull request Aug 29, 2024
wence- added a commit to wence-/polars that referenced this pull request Sep 2, 2024
The merge of pola-rs#18425 accidentally reset this to 1.5.
wence- added a commit to wence-/polars that referenced this pull request Sep 2, 2024
The merge of pola-rs#18425 accidentally reset this to 1.5.
@c-peters c-peters added the accepted Ready for implementation label Sep 3, 2024
@nameexhaustion nameexhaustion mentioned this pull request Oct 1, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation internal An internal refactor or improvement rust Related to Rust Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants