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

to_datetime may give incorrect results #9673

Closed
2 tasks done
MarcoGorelli opened this issue Jul 2, 2023 · 0 comments · Fixed by #9675
Closed
2 tasks done

to_datetime may give incorrect results #9673

MarcoGorelli opened this issue Jul 2, 2023 · 0 comments · Fixed by #9675
Labels
A-temporal Area: date/time functionality bug Something isn't working python Related to Python Polars

Comments

@MarcoGorelli
Copy link
Collaborator

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

There are a few more cases of when NaiveDateTime.parse_from_string fails, but then the fallback NaiveDate.parse_from_string passes and "chops off" some data

Reproducible example

In [7]: pl.Series(['2020-January-01 12:34']).str.to_datetime('%Y-%B-%d %M:%S')
Out[7]:
shape: (1,)
Series: '' [datetime[μs]]
[
        2020-01-01 00:00:00
]

In [8]: datetime.strptime('2020-January-01 12:34', '%Y-%B-%d %M:%S')
Out[8]: datetime.datetime(2020, 1, 1, 0, 12, 34)

In [19]: pl.Series(['2020-January-01 10:43']).str.to_datetime('%Y-%B-%d %I:%M')
Out[19]:
shape: (1,)
Series: '' [datetime[μs]]
[
        2020-01-01 00:00:00
]

In [20]: datetime.strptime('2020-January-01 10:43', '%Y-%B-%d %I:%M')
Out[20]: datetime.datetime(2020, 1, 1, 10, 43)

Expected behavior

to either raise, or match datetime.strptime

Installed versions

--------Version info---------
Polars:      0.18.4
Index type:  UInt32
Platform:    Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python:      3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0]

----Optional dependencies----
numpy:       1.24.3
pandas:      2.0.2
pyarrow:     <not installed>
connectorx:  <not installed>
deltalake:   <not installed>
fsspec:      <not installed>
matplotlib:  3.7.1
xlsx2csv:    <not installed>
xlsxwriter:  <not installed>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-temporal Area: date/time functionality bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant