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: Raise informative error instead of panicking when passing invalid directives to to_string for Date dtype #17670

Merged
merged 4 commits into from
Jul 25, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Jul 16, 2024

closes #16271

I've added apply_to_buffer_generic and try_apply_to_buffer_generic too as they'd be very useful to plugin authors (expecting them to manually re-implement this is probably unrealistic, and from tests I've done, allocating on each iteration slows things down by 3-4x)

@MarcoGorelli MarcoGorelli changed the title feat: raise informative error instead of panicking when passing invalid directives to to_string for Date dtype feat: Raise informative error instead of panicking when passing invalid directives to to_string for Date dtype Jul 16, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Jul 16, 2024
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 26 lines in your changes missing coverage. Please review.

Project coverage is 80.49%. Comparing base (26a16e3) to head (6042da8).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/polars-core/src/chunked_array/ops/apply.rs 50.00% 21 Missing ⚠️
py-polars/src/map/series.rs 50.00% 4 Missing ⚠️
...tes/polars-core/src/chunked_array/temporal/date.rs 87.50% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17670   +/-   ##
=======================================
  Coverage   80.49%   80.49%           
=======================================
  Files        1503     1503           
  Lines      197054   197049    -5     
  Branches     2805     2805           
=======================================
- Hits       158615   158613    -2     
+ Misses      37918    37915    -3     
  Partials      521      521           

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

@MarcoGorelli MarcoGorelli marked this pull request as ready for review July 17, 2024 09:59
@MarcoGorelli MarcoGorelli changed the title feat: Raise informative error instead of panicking when passing invalid directives to to_string for Date dtype WIP feat: Raise informative error instead of panicking when passing invalid directives to to_string for Date dtype Jul 18, 2024
@MarcoGorelli MarcoGorelli marked this pull request as draft July 18, 2024 17:52
@MarcoGorelli MarcoGorelli changed the title WIP feat: Raise informative error instead of panicking when passing invalid directives to to_string for Date dtype feat: Raise informative error instead of panicking when passing invalid directives to to_string for Date dtype Jul 18, 2024
@MarcoGorelli MarcoGorelli marked this pull request as ready for review July 18, 2024 21:02
@MarcoGorelli MarcoGorelli marked this pull request as draft July 19, 2024 05:47
…ng unsupported directives to `.dt.to_string`
@MarcoGorelli MarcoGorelli marked this pull request as ready for review July 22, 2024 15:14
@@ -115,6 +115,55 @@ where

ChunkedArray::try_from_chunk_iter(self.name(), iter)
}

pub fn apply_to_buffer_generic<'a, F>(&'a self, mut f: F) -> StringChunked
Copy link
Member

Choose a reason for hiding this comment

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

Except, it shouldn't be called this, as it is not generic. It returns a StringChunked/

Maybe apply_to_string_amortized?

Copy link
Collaborator Author

@MarcoGorelli MarcoGorelli Jul 23, 2024

Choose a reason for hiding this comment

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

true, I was just thinking that, respect to apply_to_buffer, the input can be any PolarsDataType

I think apply_to_string_amortized makes it sounds like the input is a String?

EDIT I guess apply_to_struct also follows this naming pattern...OK, updating 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would apply_into_string be an OK name? apply_to_string to me just reads like the string is the input rather than the output

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but change the apply_to_struct and other as well then.

.downcast_iter()
.map(|arr| {
let mut mutarr = MutablePlString::with_capacity(arr.len());
arr.iter().try_for_each(|opt| {
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this just a loop? It's a bit less cluttered with the fallible return types.

@ritchie46 ritchie46 merged commit 7137895 into pola-rs:main Jul 25, 2024
26 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 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.

Errors out when calling .strftime('%+')
2 participants