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

fix: Avoiding panic with striptime for out-of-bounds dates #21208

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hemanth94
Copy link
Contributor

Fixes #19928

When Strict is false

  • As mentioned in the issue, whenever we go out of bounds with date using nano secs it panics.
  • For Micros and Millis the code rather just shows null with out panicking. Same should happen with nano secs.

This can be tested now after commit, which shows null rather than panicking

let res = df!("d" => &["2300-01-01T00:00:00Z".to_string()])?
        .lazy()
        .with_column(col("d").str().strptime(
            DataType::Datetime(TimeUnit::Nanoseconds, None),
            StrptimeOptions {
                format: Some("%Y-%m-%dT%H:%M:%SZ".to_string().into()),
                strict: false,
                exact: true,
                cache: true,
            },
            lit("null"),
        ))
        .collect();
    println!("{}", res.unwrap());
shape: (1, 1)
┌──────────────┐
│ d            │
│ ---          │
│ datetime[ns] │
╞══════════════╡
│ null         │
└──────────────┘

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.89%. Comparing base (4eb4fb7) to head (d544a82).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #21208   +/-   ##
=======================================
  Coverage   79.89%   79.89%           
=======================================
  Files        1596     1596           
  Lines      228552   228553    +1     
  Branches     2608     2608           
=======================================
+ Hits       182607   182608    +1     
  Misses      45349    45349           
  Partials      596      596           

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

@ritchie46
Copy link
Member

Nice! Can you add a (preferably python test)?

@ritchie46 ritchie46 changed the title Fix(rust): Avoiding panic with striptime for out-of-bounds dates fix: Avoiding panic with striptime for out-of-bounds dates Feb 15, 2025
@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

err: strptime panics (instead of erroring) for out-of-bounds dates
2 participants