8000 DEP: deprecate float as axis argument to reductions, for 1.9 by juliantaylor · Pull Request #4891 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DEP: deprecate float as axis argument to reductions, for 1.9 #4891

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

Merged
Merged
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
8000
DEP: deprecate float as axis argument to reductions
consistent with deprecation of float as slice indices.
Closes gh-4876
  • Loading branch information
juliantaylor committed Jul 17, 2014
commit 5b86b763aa8381fa875820fe02f9e2293db47c23
4 changes: 2 additions & 2 deletions numpy/core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
}
for (i = 0; i < naxes; ++i) {
PyObject *tmp = PyTuple_GET_ITEM(axes_in, i);
long axis = PyInt_AsLong(tmp);
int axis = PyArray_PyIntAsInt(tmp);
if (axis == -1 && PyErr_Occurred()) {
Py_XDECREF(otype);
Py_DECREF(mp);
Expand All @@ -3771,7 +3771,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
}
/* Try to interpret axis as an integer */
else {
long axis = PyInt_AsLong(axes_in);
int axis = PyArray_PyIntAsInt(axes_in);
/* TODO: PyNumber_Index would be good to use here */
if (axis == -1 && PyErr_Occurred()) {
Py_XDECREF(otype);
Expand Down
8 changes: 8 additions & 0 deletions numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ def mult(a, b):
self.assert_not_deprecated(mult, args=([1], np.int_(3)))


def test_reduce_axis_float_index(self):
d = np.zeros((3,3,3))
self.assert_deprecated(np.min, args=(d, 0.5))
self.assert_deprecated(np.min, num=1, args=(d, (0.5, 1)))
self.assert_deprecated(np.min, num=1, args=(d, (1, 2.2)))
self.assert_deprecated(np.min, num=2, args=(d, (.2, 1.2)))


class TestBooleanArgumentDeprecation(_DeprecationTestCase):
"""This tests that using a boolean as integer argument/indexing is
deprecated.
Expand Down
0