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(rust, python)!: don't parse inputs without hour and minute components as pl.Datetime (use pl.Date instead) #8850

Closed

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented May 15, 2023

closes #8849

This makes things slightly inconvenient for anyone previously parsing '2020-01-01' as Datetime, as they need to parse Date and then cast to Datetime, but better than silently dropping the 'hour' component IMO

To clarify:

Current:

In [22]: pl.Series(['2020-01-01']).str.to_datetime('%Y-%m-%d')
Out[22]:
shape: (1,)
Series: '' [datetime[μs]]
[
        2020-01-01 00:00:00
]

Here:

In [24]: In [22]: pl.Series(['2020-01-01']).str.to_datetime('%Y-%m-%fda')
---------------------------------------------------------------------------
ComputeError: strict conversion to datetimes failed.

You might want to try:
- setting `strict=False`
- explicitly specifying a `format`
- setting `utc=True` (if you are parsing datetimes with multiple offsets)
- using `.to_date` instead of `.to_datetime`, or `.strptime(pl.Date)` instead of `.strptime(pl.Datetime)`

In [23]: pl.Series(['2020-01-01']).str.to_date('%Y-%m-%d')  # can cast to `Datetime` if they wish
Out[23]:
shape: (1,)
Series: '' [date]
[
        2020-01-01
]

@github-actions github-actions bot added breaking Change that breaks backwards compatibility fix Bug fix python Related to Python Polars rust Related to Rust Polars labels May 15, 2023
@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 15, 2023 10:12
@MarcoGorelli MarcoGorelli marked this pull request as draft May 15, 2023 11:21
@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 15, 2023 13:30
@MarcoGorelli MarcoGorelli added this to the Python Polars 0.18.0 milestone May 19, 2023
@MarcoGorelli MarcoGorelli added the do not merge This pull requests should not be merged right now label May 19, 2023
@MarcoGorelli MarcoGorelli marked this pull request as draft May 22, 2023 16:34
@ritchie46
Copy link
Member

@MarcoGorelli any update on this? Or shouldn't we include this in 0.18 and do we first need to iron things out?

@MarcoGorelli
Copy link
Collaborator Author

hey - just wanted to check we were aligned, are you on board with the reasoning in #8849 (comment) ? If so I'll resolve the conflicts and push

@MarcoGorelli
Copy link
Collaborator Author

superseded by #9044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Change that breaks backwards compatibility do not merge This pull requests should not be merged right now 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.

Parsing datehour string without zero padded hour gives wrong output
2 participants