Skip to content

Commit 6b9e63a

Browse files
sebergpmhatre1
authored andcommitted
COMPAT: Adapt to Numpy 2.0 dtype changes (pandas-dev#57780)
1 parent 48efd9d commit 6b9e63a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pandas/_libs/src/datetime/pd_datetime.c

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ 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 only) */
24+
#define PY_ARRAY_UNIQUE_SYMBOL PANDAS_DATETIME_NUMPY
25+
#include "numpy/ndarrayobject.h"
2326
#include "pandas/datetime/pd_datetime.h"
2427
#include "pandas/portable.h"
2528

@@ -255,5 +258,6 @@ static struct PyModuleDef pandas_datetimemodule = {
255258

256259
PyMODINIT_FUNC PyInit_pandas_datetime(void) {
257260
PyDateTime_IMPORT;
261+
import_array();
258262
return PyModuleDef_Init(&pandas_datetimemodule);
259263
}

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
1616

1717
// Licence at LICENSES/NUMPY_LICENSE
1818

19-
#define NO_IMPORT
20-
2119
#ifndef NPY_NO_DEPRECATED_API
2220
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
2321
#endif // NPY_NO_DEPRECATED_API
2422

2523
#include <Python.h>
2624

2725
#include "pandas/vendored/numpy/datetime/np_datetime.h"
28-
#include <numpy/ndarraytypes.h>
26+
27+
#define NO_IMPORT_ARRAY
28+
#define PY_ARRAY_UNIQUE_SYMBOL PANDAS_DATETIME_NUMPY
29+
#include <numpy/ndarrayobject.h>
2930
#include <numpy/npy_common.h>
3031

3132
#if defined(_WIN32)
@@ -1070,5 +1071,8 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
10701071
*/
10711072
PyArray_DatetimeMetaData
10721073
get_datetime_metadata_from_dtype(PyArray_Descr *dtype) {
1073-
return (((PyArray_DatetimeDTypeMetaData *)dtype->c_metadata)->meta);
1074+
#if NPY_ABI_VERSION < 0x02000000
1075+
#define PyDataType_C_METADATA(dtype) ((dtype)->c_metadata)
1076+
#endif
1077+
return ((PyArray_DatetimeDTypeMetaData *)PyDataType_C_METADATA(dtype))->meta;
10741078
}

0 commit comments

Comments
 (0)