-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: Throw TypeError on operator concat on Numpy Arrays #16570
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
Conversation
Follow up question, should we allow concat with regular arrays like
|
PyPy failure is either a (possibly unfixable) bug in PyPy, or a design problem in python itself. |
@eric-wieser Thanks a lot for the feedback, made the changes. Quick question, should we support coercion of array like types to NDarray or follow operator.concat for this case? |
The test shows an inconsistancy in Python. |
@mattip the C-Python implementation is roughly this:
I think this is correct at least in the sense that the current behaviour is undesired enough that it makes sense to do something. I would be happy, however, to implement this simply as:
if this does not work in PyPy. I agree that this is all besides the standard, but currently |
According to the documentation, |
The CPython implementation of
Inside
so it seems a situation where both Edit: @eric-wieser opened the issue. |
Well, I agree with both sides. Yes, my pseudo-code is what it does, and it implements it as So, I see the argument that we should maybe not try to do "magic" to make this work. But on the other hand, I am not sure there is a reason why not to raise an error? Since it is guaranteed that any user who does @eric-wieser noted the possibility when |
giving it some thought, @mattip makes a good point, looks like it should call nb_add, which in the case of python, which when we pass numpy arrays means broadcast and do an elemwise add. but yes very few users would expect that operator.concat would cause a broadcast followed by elemwise add and an error will help. not sure, if we go down this road though, how many more such difference in behaviors (because of numpy array being slightly different from python seq) we will have to fix. |
Perhaps we should file a python issue asking for clarification. |
In https://bugs.python.org/issue29139#msg284547, @serhiy-storchaka says:
|
Honestly, I am unwilling to fight either way. If Python really embraced it, they would need to add |
Just attempted to post to python-dev about this, |
Thanks @eric-wieser for the email, hope the clarification helps us move this in the right direction. |
Seems like the (small) discussion on the python mailing list basically converged to: Its an implementation detail, but putting an error could be fine.
EDIT: We would not really be able to test it, or at least skip it on PyPy and any other python implementation which behaves differently |
numpy/core/src/multiarray/sequence.c
Outdated
// Throw a type error, when trying to concat NDArrays | ||
if(PyArray_Check(other) || PyArray_Check(self)) { | ||
PyErr_SetString(PyExc_TypeError, | ||
"Concatenation operation is not implemented for Numpy Arrays"); |
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.
Maybe it's worth highlighting np.concatenate
in the error message? Only as long as it doesn't make things too verbose.
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.
Agreed, makes sense to redirect
You have to skip the test on PyPy (there is an |
Thank you @seberg will make the changes. |
c1edafe
to
dbfcc84
Compare
Note that this is a Python implementation detail and *not* a language standard. Users should not rely on the error being set, as it may not be set e.g. on PyPy. (See numpygh-16570 for discussion, this has been briefly discussed on Python as well: https://mail.python.org/archives/list/python-dev@python.org/message/HCXMI7LPWZEKKPRIJTVHN5ZRWIUXM5C3/ Fixes numpygh-16489
Thanks Rakesh! |
Fixes #16489
New to Python C-API, requesting feedback on Reference counter handling, does it look correct?
Tried to reuse Numpy concatenate.