Skip to content

Commit

Permalink
Backport PR pandas-dev#57780: COMPAT: Adapt to Numpy 2.0 dtype changes
Browse files Browse the repository at this point in the history
  • Loading branch information
seberg authored and meeseeksmachine committed Mar 8, 2024
1 parent e44f91d commit 189790f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pandas/_libs/src/datetime/pd_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
#include <Python.h>

#include "datetime.h"
/* Need to import_array for np_datetime.c (for NumPy 1.x support only) */
#define PY_ARRAY_UNIQUE_SYMBOL PANDAS_DATETIME_NUMPY
#include "numpy/ndarrayobject.h"
#include "pandas/datetime/pd_datetime.h"
#include "pandas/portable.h"

Expand Down Expand Up @@ -255,5 +258,6 @@ static struct PyModuleDef pandas_datetimemodule = {

PyMODINIT_FUNC PyInit_pandas_datetime(void) {
PyDateTime_IMPORT;
import_array();
return PyModuleDef_Init(&pandas_datetimemodule);
}
12 changes: 8 additions & 4 deletions pandas/_libs/src/vendored/numpy/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt

// Licence at LICENSES/NUMPY_LICENSE

#define NO_IMPORT

#ifndef NPY_NO_DEPRECATED_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif // NPY_NO_DEPRECATED_API

#include <Python.h>

#include "pandas/vendored/numpy/datetime/np_datetime.h"
#include <numpy/ndarraytypes.h>

#define NO_IMPORT_ARRAY
#define PY_ARRAY_UNIQUE_SYMBOL PANDAS_DATETIME_NUMPY
#include <numpy/ndarrayobject.h>
#include <numpy/npy_common.h>

#if defined(_WIN32)
Expand Down Expand Up @@ -1070,5 +1071,8 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td,
*/
PyArray_DatetimeMetaData
get_datetime_metadata_from_dtype(PyArray_Descr *dtype) {
return (((PyArray_DatetimeDTypeMetaData *)dtype->c_metadata)->meta);
#if NPY_ABI_VERSION < 0x02000000
#define PyDataType_C_METADATA(dtype) ((dtype)->c_metadata)
#endif
return ((PyArray_DatetimeDTypeMetaData *)PyDataType_C_METADATA(dtype))->meta;
}

0 comments on commit 189790f

Please sign in to comment.