Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH, TST: PR 31332 revisions
* Several more size/elsize related typing fixes in the descriptor
source to support the above PR, and to fix a Windows
test failure observed there (confirmed locally on Windows
box).

* Augment `test_gh_31308()` with an additional assertion
that is sensitive to the need for some of these source changes.
  • Loading branch information
tylerjereddy committed May 1, 2026
commit ae6349549671528ddf7f96b48439373300f7039a
18 changes: 9 additions & 9 deletions numpy/_core/src/multiarray/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ _convert_from_tuple(PyObject *obj, int align)
}
for (int i=0; i < shape.len; i++) {
PyTuple_SET_ITEM(newdescr->subarray->shape, i,
PyLong_FromLong((long)shape.ptr[i]));
PyLong_FromSsize_t(shape.ptr[i]));

if (PyTuple_GET_ITEM(newdescr->subarray->shape, i) == NULL) {
Py_DECREF(newdescr);
Expand Down Expand Up @@ -521,7 +521,7 @@ _convert_from_array_descr(PyObject *obj, int align)
goto fail;
}
PyTuple_SET_ITEM(tup, 0, (PyObject *)conv);
PyTuple_SET_ITEM(tup, 1, PyLong_FromLong((long) totalsize));
PyTuple_SET_ITEM(tup, 1, PyLong_FromSsize_t(totalsize));

/*
* Title can be "meta-data". Only insert it
Expand Down Expand Up @@ -642,7 +642,7 @@ _convert_from_list(PyObject *obj, int align)
}
maxalign = PyArray_MAX(maxalign, _align);
}
PyObject *size_obj = PyLong_FromLong((long) totalsize);
PyObject *size_obj = PyLong_FromSsize_t(totalsize);
if (!size_obj) {
Py_DECREF(conv);
goto fail;
Expand Down Expand Up @@ -1156,7 +1156,7 @@ _convert_from_dict(PyObject *obj, int align)
goto fail;
}

PyTuple_SET_ITEM(tup, 1, PyLong_FromLong(offset));
PyTuple_SET_ITEM(tup, 1, PyLong_FromSsize_t(offset));
/* Flag whether the fields are specified out of order */
if (offset < totalsize) {
has_out_of_order_fields = 1;
Expand All @@ -1180,7 +1180,7 @@ _convert_from_dict(PyObject *obj, int align)
if (align && _align > 1) {
totalsize = NPY_NEXT_ALIGNED_OFFSET(totalsize, _align);
}
PyTuple_SET_ITEM(tup, 1, PyLong_FromLong(totalsize));
PyTuple_SET_ITEM(tup, 1, PyLong_FromSsize_t(totalsize));
totalsize += newdescr->elsize;
}
if (len == 3) {
Expand Down Expand Up @@ -1797,7 +1797,7 @@ _convert_from_str(PyObject *obj, int align)
}

int check_num = NPY_NOTYPE + 10;
int elsize = 0;
npy_intp elsize = 0;
/* A typecode like 'd' */
if (len == 1) {
/* Python byte string characters are unsigned */
Expand All @@ -1810,7 +1810,7 @@ _convert_from_str(PyObject *obj, int align)

/* Attempt to parse the integer, make sure it's the rest of the string */
errno = 0;
long result = strtol(type + 1, &typeend, 10);
npy_intp result = strtol(type + 1, &typeend, 10);
npy_bool some_parsing_happened = !(type == typeend);
npy_bool entire_string_consumed = *typeend == '\0';
npy_bool parsing_succeeded =
Expand All @@ -1820,7 +1820,7 @@ _convert_from_str(PyObject *obj, int align)
goto fail;
}

elsize = (int)result;
elsize = result;


if (parsing_succeeded && typeend - type == len) {
Expand Down Expand Up @@ -2820,7 +2820,7 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *NPY_UNUSED(args))
elsize = -1;
alignment = -1;
}
PyTuple_SET_ITEM(state, 5, PyLong_FromLong(elsize));
PyTuple_SET_ITEM(state, 5, PyLong_FromSsize_t(elsize));
PyTuple_SET_ITEM(state, 6, PyLong_FromLong(alignment));
PyTuple_SET_ITEM(state, 7, PyLong_FromUnsignedLongLong(
self->flags & ~NPY_NOT_TRIVIALLY_COPYABLE));
Expand Down
2 changes: 2 additions & 0 deletions numpy/_core/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,8 @@ def test_signature_dtypes_classes(self, typename: str):
def test_gh_31308(kind, exp):
kind_dtype = np.dtype(kind)
Comment thread
tylerjereddy marked this conversation as resolved.
assert kind_dtype.itemsize == exp
for name in kind_dtype.names:
assert kind_dtype[name].shape[0] > 0


@pytest.mark.skipif(not IS_64BIT, reason="test requires 64-bit system")
Expand Down
Loading