-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: allow any axis for np.concatenate for 1D #440
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
BUG: allow any axis for np.concatenate for 1D #440
Conversation
if (ndim == 1 & axis != 0) { | ||
PyErr_WarnEx(PyExc_FutureWarning, | ||
"axis not 0 for ndim == 0; this will raise an error " | ||
"in future versions of numpy", 2); |
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.
PyErr_WarnEx isn't available in 2.4 (the Travis failure on this PR is real). Also technically this should be a DeprecationWarning, since it's only introducing stricter checking, not actually causing code to return a different result. Use the DEPRECATE macro from numpy/ndarrayobject.h to fix both of these.
These are nice tests and a nice check. Will you have time to update your fork so the PR can be merged automatically? |
} | ||
axis = 0; | ||
} | ||
|
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 this should be generalized by doing if (axis > ndim-1)
--> warning message, because this issue probably exists at higher dimensions as well.
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.
I think the behavior has only changed for 1D arrays. For example, in numpy 1.6.1:
In [17]: a = np.zeros((1,3)) In [18]: b = np.zeros((2,3)) In [19]: np.concatenate((a, b)) Out[19]: array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]) In [20]: np.concatenate((a, b), axis=10) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in () ----> 1 np.concatenate((a, b), axis=10) ValueError: bad axis1 argument to swapaxes
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.
Ah, I see, the current implementation has an explicit bounds-check in concatenate, but in earlier versions it already failed for multidimensional arrays in another part of the code.
Previous numpies allowed the user to pass any integer as axis argument to np.concatenate, when the input arrays were 1D. At some point we tightened up on this, raising an error for axis values other than 0. This raises a FutureWarning for axis numbers != 0, but allows them, for backwards compatibility.
Use of PyErr_WarnEx causing failure for Python 2.4.
From review by Nathaniel - thanks.
BUG: allow any axis for np.concatenate for 1D
Previous numpies allowed the user to pass any integer as axis argument
to np.concatenate, when the input arrays were 1D. At some point we
tightened up on this, raising an error for axis values other than 0.
This raises a FutureWarning for axis numbers != 0, but allows them, for
backwards compatibility.