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

API: to_datetime inconsistent returning of datetime.datetime #14487

Closed
jorisvandenbossche opened this issue Oct 24, 2016 · 7 comments · Fixed by #50242
Closed

API: to_datetime inconsistent returning of datetime.datetime #14487

jorisvandenbossche opened this issue Oct 24, 2016 · 7 comments · Fixed by #50242
Labels
Bug Datetime Datetime data dtype

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Oct 24, 2016

Copying from #14448 (comment) (as the issue is closed now):

In [1]: pd.to_datetime('13000101', errors='ignore')
Out[1]: '13000101'

In [2]: pd.to_datetime('13000101', errors='ignore', format='%Y%m%d')
Out[2]: datetime.datetime(1300, 1, 1, 0, 0)

The above inconsistency (which is also not documented at all I think), is that something we want to fix?

@jreback
Copy link
Contributor

jreback commented Oct 24, 2016

i would say we should return the same as [1]
though is it then not possible to get a datetime for out of bounds dates?

@jreback jreback added Datetime Datetime data dtype API Design labels Oct 25, 2016
@tacaswell
Copy link
Contributor

maybe bread crumbs back to #6415

@jorisvandenbossche
Copy link
Member Author

jorisvandenbossche commented May 22, 2019

It also depends on which format is specified:

In [38]: pd.to_datetime(['15010101', '20150101'], format="%Y%m%d", errors='ignore')
Out[38]: Index([1501-01-01 00:00:00, 2015-01-01 00:00:00], dtype='object')  <-- datetime.datetime objects

In [40]: pd.to_datetime(['1501-01-01', '2015-01-01'], format="%Y-%m-%d", errors='ignore')
Out[40]: Index(['1501-01-01', '2015-01-01'], dtype='object')

@jorisvandenbossche
Copy link
Member Author

On the original question of which of the two behaviours we would want: whether it is for errors='ignore' or not, I think there is some value in having the option to get datetime.datetime values for out of bound dates

@nathalier
Copy link
Contributor

Yet another example of unpredictable behaviour:

pd.to_datetime(12912, format="%Y%m%d", errors='ignore')
Out[4]: 12912
pd.to_datetime(21213, format="%Y%m%d", errors='ignore')
Out[5]: datetime.datetime(2, 12, 13, 0, 0)

@MarcoGorelli
Copy link
Member

yeah it's the %Y%m%d fastpath and its myriad of bugs

this'll be addressed in #50242

@jorisvandenbossche
Copy link
Member Author

Resolved by #50242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
No open projects
to_datetime Improvements
Boxing/Return Types
Development

Successfully merging a pull request may close this issue.

7 participants