10000 BUG: partially revert gh-28154 by ngoldbaum · Pull Request #28198 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: partially revert gh-28154 #28198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions numpy/_core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -1829,11 +1829,14 @@ PyArray_CheckFromAny_int(PyObject *op, PyArray_Descr *in_descr,
{
PyObject *obj;
if (requires & NPY_ARRAY_NOTSWAPPED) {
if (!in_descr && PyArray_Check(op)) {
in_descr = PyArray_DESCR((PyArrayObject *)op);
Py_INCREF(in_descr);
if (!in_descr && PyArray_Check(op) &&
PyArray_ISBYTESWAPPED((PyArrayObject* )op)) {
in_descr = PyArray_DescrNew(PyArray_DESCR((PyArrayObject *)op));
if (in_descr == NULL) {
return NULL;
}
}
if (in_descr) {
else if (in_descr && !PyArray_ISNBO(in_descr->byteorder)) {
PyArray_DESCR_REPLACE_CANONICAL(in_descr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we go all the way back and not use PyArray_DESCR_REPLACE_CANONICAL for backport?
(Basically, just adding the extra !PyArray_ISNBO(in_descr->byteorde).

But if not, this looks fine. It'll solve the crash-regression for sure, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes more sense to do to the 2.2.x branch than to main. I'd rather use ensure_canonical in more places. I'll just go ahead and make another PR to the stable branch with the minimal change, just in case there are other structured dtype breakages that didn't get so quickly reported.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #28201

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but that means you need to make a different/dedicated backport PR against 2.2.x? (If I think about it again, for main we could potentially keep the code exactly as is, the bug may be only in searchsorted (the bug being that the dtype passed in may be replaced, so one cannot keep using it).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the backport. I'll have another look at searchsorted, maybe we can just fix it up there (and maybe add a brief release note just in case).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Feel free to close this if you come up with an alternate fix.

}
}
Expand Down
6 changes: 6 additions & 0 deletions numpy/_core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2653,3 +2653,9 @@ def test_sort_overlap(self):
inp = np.linspace(0, size, num=size, dtype=np.intc)
out = np.sort(inp)
assert_equal(inp, out)

def test_searchsorted_structured(self):
# gh-28190
x = np.array([(0, 1.)], dtype=[('time', '<i8'), ('value', '<f8')])
y = np.array((0, 0.), dtype=[('time', '<i8'), ('value', '<f8')])
x.searchsorted(y)
Loading
0