Skip to content

BUG: Bug in .to_datetime() when passing integers or floats, no unit and errors=coerce #13183

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

Closed
wants to merge 1 commit into from

Conversation

jreback
Copy link
Contributor

@jreback jreback commented May 15, 2016

closes #13180

@jreback
Copy link
Contributor Author

jreback commented May 15, 2016

@jorisvandenbossche

note that prior to 0.18.1 we would handle

pd.to_datetime([1]) with unit='ns' as the default. This PR addresses this, but after looking again, should we make the user specify it here (when it IS ns), e.g. as in the accompanied issue.

@jreback
Copy link
Contributor Author

jreback commented May 18, 2016

any comments @jorisvandenbossche

@melzoghbi
Copy link

I have pandas version 0.19.2 and i still get this error when using to_datetime() method. My column type is int64 and here is the error message when i use the following:
image

  1. pd.to_datetime(ds['createdTime'], unit='s') --> OutOfBoundsDatetime: cannot convert input with unit 's'

  2. pd.to_datetime(ds['createdTime']) --> no conversion

image

Any idea how to fix this? Thanks a lot.

@jorisvandenbossche
Copy link
Member

@melzoghbi if you still have an issue, please open a new issue (as your example is not related to the above issue). However, please first make sure to test on the latest pandas (0.21.0) and make sure to have an actual reproducible examples (so copy-pasteable code, not as an image).

Further, for me this actually converts to a datetime:

In [121]: s = pd.Series([1508258340299])

In [122]: pd.to_datetime(s)
Out[122]: 
0   1970-01-01 00:25:08.258340299
dtype: datetime64[ns]

@melzoghbi
Copy link

melzoghbi commented Nov 14, 2017

Thanks for your help and this actually shows the datetime but not the actual date that i am looking for.

For example:
import pandas as pd
s = pd.Series([1510675225])
pd.to_datetime(s)

Should show a date as 11/14/27 but it actually shows epoch time as of 1970 datetime.

Any way i will open a new issue for this.

@hashamMunir
Copy link

issue persists in pd 0.23.3
converting the unixtime to date time.
1970-01-01 00:00:01.529009633
it returns 1970

@pushyamig
Copy link

this is still an issue in the Pandas 0.23.4, is there any workaround?

@jorisvandenbossche
Copy link
Member

This is a closed issue that is fixed. If you think there is still a bug, please open a new issue with a reproducible example.

If it is about the year 1970, that is not a bug but because to_datetime interprets integers as nanoseconds by default:

In [11]: s = pd.Series([1510675225])

In [12]: pd.to_datetime(s)
Out[12]: 
0   1970-01-01 00:00:01.510675225
dtype: datetime64[ns]

In [13]: pd.to_datetime(s, unit='s')
Out[13]: 
0   2017-11-14 16:00:25
dtype: datetime64[ns]

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
None yet
Development

Successfully merging this pull request may close these issues.

Converting float64 values to datetime64[ns] format using pd.to_datetime results in NaT if errors='coerce'
5 participants