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: Do not panic in strptime() if format ends with '%' #21176

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

etiennebacher
Copy link
Contributor

import polars as pl
df=pl.DataFrame({"a": ["2020-01-01"]})
df.select(pl.col("a").str.strptime(pl.Date, format="d%"))

Before:

pyo3_runtime.PanicException: invalid pattern

After:

polars.exceptions.InvalidOperationError: conversion from `str` to `date` failed in column 'a' for 1 out of 1 values: ["2020-01-01"]

You might want to try:
- setting `strict=False` to set values that cannot be converted to `null`
- using `str.strptime`, `str.to_date`, or `str.to_datetime` and providing a format string

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Feb 10, 2025
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.82%. Comparing base (d15bfe5) to head (0d5c34c).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21176      +/-   ##
==========================================
- Coverage   79.88%   79.82%   -0.07%     
==========================================
  Files        1593     1593              
  Lines      227640   227642       +2     
  Branches     2600     2600              
==========================================
- Hits       181856   181708     -148     
- Misses      45187    45337     +150     
  Partials      597      597              

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

@ritchie46 ritchie46 merged commit 0654544 into pola-rs:main Feb 11, 2025
28 checks passed
@etiennebacher etiennebacher deleted the panic-strptime branch February 11, 2025 15:45
braaannigan pushed a commit to braaannigan/polars that referenced this pull request Feb 12, 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.

2 participants