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

BUG: underflow on Timestamp creation #14433

Merged
merged 3 commits into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
undo change to lower bound
  • Loading branch information
chris-b1 committed Oct 20, 2016
commit df279e5486c3591cd401510fb76f0bc2c3654894
9 changes: 2 additions & 7 deletions pandas/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,8 @@ cdef int64_t NPY_NAT = util.get_nat()
ctypedef unsigned char UChar

cimport util
from util cimport is_array, _checknull, _checknan

cdef extern from "headers/stdint.h":
enum: UINT8_MAX
enum: INT64_MAX
enum: INT64_MIN

from util cimport (is_array, _checknull, _checknan, INT64_MAX,
INT64_MIN, UINT8_MAX)

cdef extern from "math.h":
double sqrt(double x)
Expand Down
16 changes: 3 additions & 13 deletions pandas/src/inference.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@ iNaT = util.get_nat()

cdef bint PY2 = sys.version_info[0] == 2

cdef extern from "headers/stdint.h":
enum: UINT8_MAX
enum: UINT16_MAX
enum: UINT32_MAX
enum: UINT64_MAX
enum: INT8_MIN
enum: INT8_MAX
enum: INT16_MIN
enum: INT16_MAX
enum: INT32_MAX
enum: INT32_MIN
enum: INT64_MAX
enum: INT64_MIN
from util cimport (UINT8_MAX, UINT16_MAX, UINT32_MAX, UINT64_MAX,
INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX,
INT32_MAX, INT32_MIN, INT64_MAX, INT64_MIN)

# core.common import for fast inference checks

Expand Down
14 changes: 14 additions & 0 deletions pandas/src/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ ctypedef fused numeric:
cnp.float32_t
cnp.float64_t

cdef extern from "headers/stdint.h":
enum: UINT8_MAX
enum: UINT16_MAX
enum: UINT32_MAX
enum: UINT64_MAX
enum: INT8_MIN
enum: INT8_MAX
enum: INT16_MIN
enum: INT16_MAX
enum: INT32_MAX
enum: INT32_MIN
enum: INT64_MAX
enum: INT64_MIN

cdef inline object get_value_at(ndarray arr, object loc):
cdef:
Py_ssize_t i, sz
Expand Down
13 changes: 6 additions & 7 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ from cpython cimport (
)


cdef extern from "headers/stdint.h":
enum: INT64_MAX
enum: INT64_MIN

# Cython < 0.17 doesn't have this in cpython
cdef extern from "Python.h":
cdef PyTypeObject *Py_TYPE(object)
Expand All @@ -42,7 +38,7 @@ from datetime cimport cmp_pandas_datetimestruct
from libc.stdlib cimport free

from util cimport (is_integer_object, is_float_object, is_datetime64_object,
is_timedelta64_object)
is_timedelta64_object, INT64_MAX)
cimport util

from datetime cimport *
Expand Down Expand Up @@ -909,9 +905,12 @@ cpdef object get_value_box(ndarray arr, object loc):


# Add the min and max fields at the class level
# INT64_MIN is reserved for NaT
cdef int64_t _NS_LOWER_BOUND = INT64_MIN + 1
cdef int64_t _NS_UPPER_BOUND = INT64_MAX
# smallest value we could actually represent is
# INT64_MIN + 1 == -9223372036854775807
# but to allow overflow free conversion with a microsecond resolution
# use the smallest value with a 0 nanosecond unit
cdef int64_t _NS_LOWER_BOUND = -9223285636854775000LL

cdef pandas_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS
pandas_datetime_to_datetimestruct(_NS_LOWER_BOUND, PANDAS_FR_ns, &_NS_MIN_DTS)
Expand Down