Skip to content

Commit 842b7c1

Browse files
committed
updates
1 parent d2a1014 commit 842b7c1

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

pandas/_libs/src/vendored/numpy/datetime/np_datetime.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2222
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
2323
#endif // NPY_NO_DEPRECATED_API
2424

25-
#include <Python.h>
26-
2725
#include "pandas/vendored/numpy/datetime/np_datetime.h"
26+
#include <Python.h>
2827
#include <numpy/arrayobject.h>
2928
#include <numpy/arrayscalars.h>
3029
#include <numpy/ndarraytypes.h>
30+
#include <stdbool.h>
3131

3232
#if defined(_WIN32)
3333
#ifndef ENABLE_INTSAFE_SIGNED_FUNCTIONS
@@ -70,12 +70,15 @@ _Static_assert(0, "__has_builtin not detected; please try a newer compiler");
7070
#endif
7171
#endif
7272

73+
#define XSTR(a) STR(a)
74+
#define STR(a) #a
75+
7376
#define PD_CHECK_OVERFLOW(FUNC) \
7477
do { \
7578
if ((FUNC) != 0) { \
7679
PyGILState_STATE gstate = PyGILState_Ensure(); \
7780
PyErr_SetString(PyExc_OverflowError, \
78-
"Overflow occurred in npy_datetimestruct_to_datetime"); \
81+
"Overflow occurred at " __FILE__ ":" XSTR(__LINE__)); \
7982
PyGILState_Release(gstate); \
8083
return -1; \
8184
} \
@@ -442,6 +445,15 @@ npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,
442445
}
443446

444447
const int64_t days = get_datetimestruct_days(dts);
448+
if (days == -1) {
449+
PyGILState_STATE gstate = PyGILState_Ensure();
450+
bool did_error = PyErr_Occurred() ? false : true;
451+
PyGILState_Release(gstate);
452+
if (did_error) {
453+
return -1;
454+
}
455+
}
456+
445457
if (base == NPY_FR_D) {
446458
return days;
447459
}

pandas/tests/frame/test_constructors.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,11 +3198,8 @@ def test_from_out_of_bounds_ns_datetime(
31983198

31993199
def test_out_of_s_bounds_datetime64(self, constructor):
32003200
scalar = np.datetime64(np.iinfo(np.int64).max, "D")
3201-
result = constructor(scalar)
3202-
item = get1(result)
3203-
assert type(item) is np.datetime64
3204-
dtype = tm.get_dtype(result)
3205-
assert dtype == object
3201+
with pytest.raises(OverflowError, match="Overflow occurred"):
3202+
constructor(scalar)
32063203

32073204
@pytest.mark.parametrize("cls", [timedelta, np.timedelta64])
32083205
def test_from_out_of_bounds_ns_timedelta(

0 commit comments

Comments
 (0)