Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 62e905a

Browse files
committed
changes for np2
1 parent 29bbbdb commit 62e905a

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

arraymap.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ typedef enum KeysArrayType{
8686
NPY_DATETIMEUNIT
8787
dt_unit_from_array(PyArrayObject* a) {
8888
// This is based on get_datetime_metadata_from_dtype in the NumPy source, but that function is private. This does not check that the dytpe is of the appropriate type.
89-
PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyArray_DESCR(a)->c_metadata)->meta);
89+
PyArray_Descr* dt = PyArray_DESCR(a); // borrowed ref
90+
PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyDataType_C_METADATA(dt))->meta);
9091
return dma->base;
9192
}
9293

@@ -941,7 +942,7 @@ lookup_hash_unicode(
941942
Py_ssize_t table_pos = hash & mask;
942943

943944
PyArrayObject *a = (PyArrayObject *)self->keys;
944-
Py_ssize_t dt_size = PyArray_DESCR(a)->elsize / UCS4_SIZE;
945+
Py_ssize_t dt_size = PyArray_ITEMSIZE(a) / UCS4_SIZE;
945946
Py_ssize_t cmp_bytes = Py_MIN(key_size, dt_size) * UCS4_SIZE;
946947

947948
Py_hash_t h = 0;
@@ -983,7 +984,7 @@ lookup_hash_string(
983984
Py_ssize_t table_pos = hash & mask;
984985

985986
PyArrayObject *a = (PyArrayObject *)self->keys;
986-
Py_ssize_t dt_size = PyArray_DESCR(a)->elsize;
987+
Py_ssize_t dt_size = PyArray_ITEMSIZE(a);
987988
Py_ssize_t cmp_bytes = Py_MIN(key_size, dt_size);
988989

989990
Py_hash_t h = 0;
@@ -1284,7 +1285,7 @@ lookup_unicode(FAMObject *self, PyObject* key) {
12841285
return -1;
12851286
}
12861287
PyArrayObject *a = (PyArrayObject *)self->keys;
1287-
Py_ssize_t dt_size = PyArray_DESCR(a)->elsize / UCS4_SIZE;
1288+
Py_ssize_t dt_size = PyArray_ITEMSIZE(a) / UCS4_SIZE;
12881289
// if the key_size is greater than the dtype size of the array, we know there cannot be a match
12891290
Py_ssize_t k_size = PyUnicode_GetLength(key);
12901291
if (k_size > dt_size) {
@@ -1305,7 +1306,7 @@ lookup_string(FAMObject *self, PyObject* key) {
13051306
return -1;
13061307
}
13071308
PyArrayObject *a = (PyArrayObject *)self->keys;
1308-
Py_ssize_t dt_size = PyArray_DESCR(a)->elsize;
1309+
Py_ssize_t dt_size = PyArray_ITEMSIZE(a);
13091310
Py_ssize_t k_size = PyBytes_GET_SIZE(key);
13101311
if (k_size > dt_size) {
13111312
return -1;
@@ -1650,7 +1651,7 @@ copy_to_new(PyTypeObject *cls, FAMObject *self, FAMObject *new)
16501651
new->key_buffer = NULL;
16511652
if (new->keys_array_type == KAT_UNICODE) {
16521653
PyArrayObject *a = (PyArrayObject *)new->keys;
1653-
Py_ssize_t dt_size = PyArray_DESCR(a)->elsize / UCS4_SIZE;
1654+
Py_ssize_t dt_size = PyArray_ITEMSIZE(a) / UCS4_SIZE;
16541655
new->key_buffer = (Py_UCS4*)PyMem_Malloc((dt_size+1) * UCS4_SIZE);
16551656
}
16561657

@@ -1831,7 +1832,7 @@ get(FAMObject *self, PyObject *key, PyObject *missing) {
18311832
# define GET_ALL_FLEXIBLE(char_type, get_end_func, lookup_func, hash_func, to_obj_func) \
18321833
{ \
18331834
char_type* v; \
1834-
Py_ssize_t dt_size = PyArray_DESCR(key_array)->elsize / sizeof(char_type);\
1835+
Py_ssize_t dt_size = PyArray_ITEMSIZE(key_array) / sizeof(char_type);\
18351836
Py_ssize_t k_size; \
18361837
for (; i < key_size; i++) { \
18371838
v = (char_type*)PyArray_GETPTR1(key_array, i); \
@@ -2019,7 +2020,7 @@ fam_get_all(FAMObject *self, PyObject *key) {
20192020
# define GET_ANY_FLEXIBLE(char_type, get_end_func, lookup_func, hash_func) \
20202021
{ \
20212022
char_type* v; \
2022-
Py_ssize_t dt_size = PyArray_DESCR(key_array)->elsize / sizeof(char_type);\
2023+
Py_ssize_t dt_size = PyArray_ITEMSIZE(key_array) / sizeof(char_type);\
20232024
Py_ssize_t k_size; \
20242025
for (; i < key_size; i++) { \
20252026
v = (char_type*)PyArray_GETPTR1(key_array, i); \
@@ -2539,13 +2540,13 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
25392540
break;
25402541
case KAT_UNICODE: {
25412542
// Over allocate buffer by 1 so there is room for null at end. This buffer is only used in lookup();
2542-
Py_ssize_t dt_size = PyArray_DESCR(a)->elsize / UCS4_SIZE;
2543+
Py_ssize_t dt_size = PyArray_ITEMSIZE(a) / UCS4_SIZE;
25432544
fam->key_buffer = (Py_UCS4*)PyMem_Malloc((dt_size+1) * UCS4_SIZE);
25442545
INSERT_FLEXIBLE(Py_UCS4, insert_unicode, ucs4_get_end_p);
25452546
break;
25462547
}
25472548
case KAT_STRING: {
2548-
Py_ssize_t dt_size = PyArray_DESCR(a)->elsize;
2549+
Py_ssize_t dt_size = PyArray_ITEMSIZE(a);
25492550
INSERT_FLEXIBLE(char, insert_string, char_get_end_p);
25502551
break;
25512552
}

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def get_ext_dir(*components: tp.Iterable[str]) -> tp.Sequence[str]:
2222
extension = setuptools.Extension(
2323
"arraymap",
2424
["arraymap.c"],
25-
include_dirs=get_ext_dir("numpy", "core", "include"),
26-
library_dirs=get_ext_dir("numpy", "core", "lib"),
25+
include_dirs=get_ext_dir("numpy", "_core", "include"),
26+
library_dirs=get_ext_dir("numpy", "_core", "lib"),
2727
define_macros=[("AM_VERSION", AM_VERSION)],
2828
libraries=["npymath"],
2929
)

0 commit comments

Comments
 (0)