Skip to content

convert integer to datetime bug, Python int too large to convert to C long #10987

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
poc7667 opened this issue Sep 4, 2015 · 11 comments
Closed
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@poc7667
Copy link

poc7667 commented Sep 4, 2015

pandas version pandas (0.16.1)

for field in ["release_date", "date"]:
    if field in df:
        df[field] = pd.to_datetime(df[field], unit="ms")

@jorisvandenbossche
Copy link
Member

Which version are you using?

In [30]: pd.to_datetime(1430784000000, unit='ms')
Out[30]: Timestamp('2015-05-05 00:00:00')

In [31]: pd.__version__
Out[31]: '0.16.2'

@jorisvandenbossche
Copy link
Member

Sorry, you did specify the version. Can you give a reprodicible example? (make up some dummy data that gives you this error)
For a small example (see above), it works for me on 0.16.2

@jreback
Copy link
Contributor

jreback commented Sep 4, 2015

ok on 0.16.1 as well.

In [1]: pd.to_datetime(1430784000000, unit='ms')
Out[1]: Timestamp('2015-05-05 00:00:00')

In [2]: pd.__version__
Out[2]: '0.16.1'

You get this error if the unit you pass is incompatible

In [4]: pd.to_datetime(1430784000000, unit='s')
OverflowError: Python int too large to convert to C long

@jreback jreback added Datetime Datetime data dtype Usage Question labels Sep 4, 2015
@wmacmillan
Copy link

Just to clarify on @jreback's point here, if the time since epoch is recorded in milliseconds, and you select seconds as your unit, you get this very unhelpful error.

@jreback
Copy link
Contributor

jreback commented Mar 9, 2016

yeah, we should prob just catch this and re-raise as a more helpful error message. Want to do a PR?

@jreback jreback added Difficulty Novice Error Reporting Incorrect or improved errors from pandas and removed Usage Question labels Mar 9, 2016
@jreback jreback added this to the 0.18.1 milestone Mar 9, 2016
@jreback jreback modified the milestones: Next Major Release, 0.18.1 Apr 25, 2016
@dreamgonfly
Copy link

Here is the error message i got when i tried to regenerate this issue. It looks like it already has been solved. Should we close this issue?

In [1]: pd.to_datetime(1430784000000, unit='s')
Out[1]: OutOfBoundsDatetime: cannot convert input with unit 's'

In [2]: pd.__version__
Out[2]: '0.18.1'

@jreback
Copy link
Contributor

jreback commented Aug 15, 2016

yes, a number of issues have touched on this recently. I don't think any more tests are necessary.

closing as fixed.

@jreback jreback closed this as completed Aug 15, 2016
@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Aug 15, 2016

Tests were added here: #13183

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.19.0, Next Major Release Aug 15, 2016
@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 i still get errors or no conversion.

Check this issue post: #13183

Thanks.

@hashamMunir
Copy link

OutOfBoundsDatetime: cannot convert input with unit 's'
issue in
print(pd.version)
0.23.3
I have pd df containing the dates in unix timestamp.

@vaibhavjaitly
Copy link

vaibhavjaitly commented Apr 16, 2020

#Time = data['timestamp']
x = datetime(20160301103842, 'Y%m%d%H%M%S')
x

OverflowError: Python int too large to convert to C lon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

8 participants