Skip to content
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

Merged
merged 3 commits into from
Sep 24, 2012

Conversation

matthew-brett
Copy link
Contributor

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.

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);
Copy link
Member

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.

@87 87 mentioned this pull request Sep 15, 2012
@teoliphant
Copy link
Member

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;
}

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.
njsmith added a commit that referenced this pull request Sep 24, 2012
BUG: allow any axis for np.concatenate for 1D
@njsmith njsmith merged commit 6a847ef into numpy:master Sep 24, 2012
@certik certik mentioned this pull request Sep 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants