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

Inconsistent behavior in Timestamp for large negative values #14415

Closed
ssanderson opened this Issue Oct 13, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@ssanderson
Contributor

ssanderson commented Oct 13, 2016

A small, complete example of the issue

# Your code here
In [1]: import numpy as np; import pandas as pd
In [3]: pd.Timestamp(np.iinfo(np.int64).min + 80000000000000)
Out[3]: Timestamp('2262-04-11 22:26:03.145224192')

In [4]: pd.Timestamp(np.iinfo(np.int64).min + 90000000000000)
Out[4]: Timestamp('1677-09-22 01:12:43.145224192')

In [5]: pd.Timestamp(np.iinfo(np.int64).min + 85000000000000)
---------------------------------------------------------------------------
OutOfBoundsDatetime                       Traceback (most recent call last)
<ipython-input-5-47bf9ab2ad0f> in <module>()
----> 1 pd.Timestamp(np.iinfo(np.int64).min + 85000000000000)

pandas/tslib.pyx in pandas.tslib.Timestamp.__new__ (pandas/tslib.c:9932)()

pandas/tslib.pyx in pandas.tslib.convert_to_tsobject (pandas/tslib.c:26453)()

pandas/tslib.pyx in pandas.tslib._check_dts_bounds (pandas/tslib.c:30034)()

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2262-04-11 23:49:23

Expected Output

I would expect all the values listed above to evaluate to dates in the 1600s. The behavior here looks like there might be a signed integer overflow happening in C somewhere, which is a little nerve-wracking since that's undefined behavior unless pandas is compiled with -fwrapv.

Output of pd.show_versions()

# Paste the output here

In [8]: pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Linux
OS-release: 4.2.0-16-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.19.0
nose: None
pip: 8.1.2
setuptools: 28.3.0
Cython: None
numpy: 1.11.2
scipy: None
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None

@chris-b1

This comment has been minimized.

Show comment
Hide comment
@chris-b1

chris-b1 Oct 13, 2016

Contributor

Also goes wrong with numpy - so probably something in here that's causing an overflow, although there really shouldn't be.

convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta,

In [131]: np.datetime64(np.iinfo(np.int64).min + 80000000000000, 'ns')
Out[131]: numpy.datetime64('2262-04-11T22:26:03.145224192')
Contributor

chris-b1 commented Oct 13, 2016

Also goes wrong with numpy - so probably something in here that's causing an overflow, although there really shouldn't be.

convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta,

In [131]: np.datetime64(np.iinfo(np.int64).min + 80000000000000, 'ns')
Out[131]: numpy.datetime64('2262-04-11T22:26:03.145224192')
@chris-b1

This comment has been minimized.

Show comment
Hide comment
@chris-b1

chris-b1 Oct 13, 2016

Contributor

Right here -

set_datetimestruct_days((dt - (perday-1)) / perday, out);

Contributor

chris-b1 commented Oct 13, 2016

Right here -

set_datetimestruct_days((dt - (perday-1)) / perday, out);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment