-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
MAINT: Clarify the error message for resize failure #12121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording is "use the resize function", not "use the resize method". Perhaps it would be clearer to say use the np.resize function
reshape
is not a substitute for resize
.
26c53c7
to
01ee56a
Compare
Thanks, I changed to just propose |
numpy/core/src/multiarray/shape.c
Outdated
@@ -108,7 +108,7 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck, | |||
PyErr_SetString(PyExc_ValueError, | |||
"cannot resize an array that " | |||
"references or is referenced\n" | |||
"by another array in this way. Use the resize function"); | |||
"by another array in this way. Use the np.resize function or refcheck=False"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct - passing refcheck = False
doesn't help if PyArray_BASE(arr)
is set.
Either:
- remove the remark about refcheck
- Split this
if
into two ifs, and only mention refcheck in the one whererefcnt > 2
is true.
01ee56a
to
a82b339
Compare
Thanks, fixed by the later way. |
numpy/core/src/multiarray/shape.c
Outdated
PyErr_SetString(PyExc_ValueError, | ||
"cannot resize an array that " | ||
"references or is referenced\n" | ||
"by another array in this way. Use the np.resize function."); | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow up, you could move this check to be done before the other two. As you have it, there are cases where the user sees "A is not allowed, try B or C", then tries B and gets "B is not allowed, try C". If you move this check first, then the user will see "A is not allowed, try C", and fix it in one step.
a82b339
to
7131b69
Compare
Thanks, applied your advice. |
Would be great to add a test for that code path that codecov complains about. Creating a |
Thanks. Please let me know if test location is wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good assuming tests pass
Thanks @kngwyu |
Fails for wheel tests on Python 3.7. See here. |
Curerntly
causes this error.
But, I feel it odd to tell users to use
resize
, whenresize
fails.