Skip to content

Commit

Permalink
dont suggest exact for to_time
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Aug 7, 2023
1 parent 0d970ba commit 795a138
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions crates/polars-plan/src/dsl/function_expr/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,34 +424,41 @@ fn handle_temporal_parsing_error(
ca: &Utf8Chunked,
out: &Series,
format: Option<&str>,
has_non_exact_option: bool,
) -> PolarsResult<()> {
let failure_mask = !ca.is_null() & out.is_null();
let all_failures = ca.filter(&failure_mask)?;
let first_failures = all_failures.unique()?.slice(0, 10).sort(false);
let n_failures = all_failures.len();
let n_failures_unique = all_failures.n_unique()?;
let addendum;
let exact_addendum = if has_non_exact_option {
"- setting `exact=False` (note: this is much slower!)\n"
} else {
""
};
let format_addendum;
if let Some(format) = format {
addendum = format!(
"checking whether the format provided ('{}') is correct",
format_addendum = format!(
"- checking whether the format provided ('{}') is correct",
format
);
} else {
addendum = String::from("explicitly specifying a `format`");
format_addendum = String::from("- explicitly specifying `format`");
}
polars_bail!(
ComputeError:
"strict {} parsing failed for {} value(s) ({} unique): {}\n\
\n\
You might want to try:\n\
- setting `strict=False`\n\
- setting `exact=False` (note: this is much slower!)\n\
- {}",
{}\
{}",
out.dtype(),
n_failures,
n_failures_unique,
first_failures.into_series().fmt_list(),
addendum,
exact_addendum,
format_addendum,
)
}

Expand All @@ -469,7 +476,7 @@ fn to_date(s: &Series, options: &StrptimeOptions) -> PolarsResult<Series> {
};

if options.strict && ca.null_count() != out.null_count() {
handle_temporal_parsing_error(ca, &out, options.format.as_deref())?;
handle_temporal_parsing_error(ca, &out, options.format.as_deref(), true)?;
}
Ok(out.into_series())
}
Expand Down Expand Up @@ -512,7 +519,7 @@ fn to_datetime(
};

if options.strict && ca.null_count() != out.null_count() {
handle_temporal_parsing_error(ca, &out, options.format.as_deref())?;
handle_temporal_parsing_error(ca, &out, options.format.as_deref(), true)?;
}
Ok(out.into_series())
}
Expand All @@ -529,7 +536,7 @@ fn to_time(s: &Series, options: &StrptimeOptions) -> PolarsResult<Series> {
.into_series();

if options.strict && ca.null_count() != out.null_count() {
handle_temporal_parsing_error(ca, &out, options.format.as_deref())?;
handle_temporal_parsing_error(ca, &out, options.format.as_deref(), false)?;
}
Ok(out.into_series())
}
Expand Down

0 comments on commit 795a138

Please sign in to comment.