8000 Merge pull request #4891 from juliantaylor/reduce-float-axis · numpy/numpy@99329f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99329f9

Browse files
committed
Merge pull request #4891 from juliantaylor/reduce-float-axis
DEP: deprecate float as axis argument to reductions, for 1.9
2 parents e85290a + 5b86b76 commit 99329f9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

numpy/core/src/umath/ufunc_object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,7 +3750,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
37503750
}
37513751
for (i = 0; i < naxes; ++i) {
37523752
PyObject *tmp = PyTuple_GET_ITEM(axes_in, i);
3753-
long axis = PyInt_AsLong(tmp);
3753+
int axis = PyArray_PyIntAsInt(tmp);
37543754
if (axis == -1 && PyErr_Occurred()) {
37553755
Py_XDECREF(otype);
37563756
Py_DECREF(mp);
@@ -3771,7 +3771,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
37713771
}
37723772
/* Try to interpret axis as an integer */
37733773
else {
3774-
long axis = PyInt_AsLong(axes_in);
3774+
int axis = PyArray_PyIntAsInt(axes_in);
37753775
/* TODO: PyNumber_Index would be good to use here */
37763776
if (axis == -1 && PyErr_Occurred()) {
37773777
Py_XDECREF(otype);

numpy/core/tests/test_deprecations.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ def mult(a, b):
249249
self.assert_not_deprecated(mult, args=([1], np.int_(3)))
250250

251251

252+
def test_reduce_axis_float_index(self):
253+
d = np.zeros((3,3,3))
254+
self.assert_deprecated(np.min, args=(d, 0.5))
255+
self.assert_deprecated(np.min, num=1, args=(d, (0.5, 1)))
256+
self.assert_deprecated(np.min, num=1, args=(d, (1, 2.2)))
257+
self.assert_deprecated(np.min, num=2, args=(d, (.2, 1.2)))
258+
259+
252260
class TestBooleanArgumentDeprecation(_DeprecationTestCase):
253261
"""This tests that using a boolean as integer argument/indexing is
254262
deprecated.

0 commit comments

Comments
 (0)
0