Skip to content

Commit b0de2fe

Browse files
seberglithomas1
andcommitted
COMPAT: Adapt to Numpy 2.0 dtype changes
Based on Thomas Li's work, but wanted to try and see that this is right. Co-authored-by: Thomas Li <[email protected]>
1 parent bf171d1 commit b0de2fe

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pandas/_libs/src/datetime/pd_datetime.c

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2020
#include <Python.h>
2121

2222
#include "datetime.h"
23+
/* Need to import_array for np_datetime.c (for NumPy 1.x support) */
24+
#include "numpy/ndarrayobject.h"
2325
#include "pandas/datetime/pd_datetime.h"
2426
#include "pandas/portable.h"
2527

@@ -255,5 +257,6 @@ static struct PyModuleDef pandas_datetimemodule = {
255257

256258
PyMODINIT_FUNC PyInit_pandas_datetime(void) {
257259
PyDateTime_IMPORT;
260+
import_array();
258261
return PyModuleDef_Init(&pandas_datetimemodule);
259262
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
1616

1717
// Licence at LICENSES/NUMPY_LICENSE
1818

19-
#define NO_IMPORT
19+
#define NO_IMPORT_ARRAY
2020

2121
#ifndef NPY_NO_DEPRECATED_API
2222
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
@@ -25,7 +25,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2525
#include <Python.h>
2626

2727
#include "pandas/vendored/numpy/datetime/np_datetime.h"
28-
#include <numpy/ndarraytypes.h>
28+
#include <numpy/ndarrayobject.h>
2929
#include <numpy/npy_common.h>
3030

3131
#if defined(_WIN32)
@@ -1070,5 +1070,8 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
10701070
*/
10711071
PyArray_DatetimeMetaData
10721072
get_datetime_metadata_from_dtype(PyArray_Descr *dtype) {
1073-
return (((PyArray_DatetimeDTypeMetaData *)dtype->c_metadata)->meta);
1073+
#if NPY_ABI_VERSION < 0x02000000
1074+
#define PyDataType_C_METADATA(dtype) ((dtype)->c_metadata)
1075+
#endif
1076+
return ((PyArray_DatetimeDTypeMetaData *)PyDataType_C_METADATA(dtype))->meta;
10741077
}

0 commit comments

Comments
 (0)