From a6a2c601c28687e8ff8b44f5319280b20a9c3f71 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 6 Jun 2013 14:59:50 +0200 Subject: [PATCH] STY: Style fixes for integer deprecation changes Also minor changes in the documentation. --- numpy/core/src/multiarray/conversion_utils.c | 22 +++++++++++--------- numpy/core/tests/test_deprecations.py | 3 +-- numpy/lib/shape_base.py | 2 +- numpy/random/tests/test_regression.py | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c index 91243d1b7802..267b502d935c 100644 --- a/numpy/core/src/multiarray/conversion_utils.c +++ b/numpy/core/src/multiarray/conversion_utils.c @@ -191,7 +191,7 @@ PyArray_AxisConverter(PyObject *obj, int *axis) *axis = NPY_MAXDIMS; } else { - *axis = (int) PyArray_PyIntAsInt(obj); + *axis = PyArray_PyIntAsInt(obj); if (PyErr_Occurred()) { return NPY_FAIL; } @@ -812,7 +812,7 @@ PyArray_PyIntAsIntp(PyObject *o) #if (NPY_SIZEOF_LONGLONG > NPY_SIZEOF_INTP) if ((long_value < NPY_MIN_INTP) || (long_value > NPY_MAX_INTP)) { PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to C numpy.intp"); + "Python int too large to convert to C numpy.intp"); return -1; } #endif @@ -820,7 +820,7 @@ PyArray_PyIntAsIntp(PyObject *o) #if (NPY_SIZEOF_LONG > NPY_SIZEOF_INTP) if ((long_value < NPY_MIN_INTP) || (long_value > NPY_MAX_INTP)) { PyErr_SetString(PyExc_OverflowError, - "Python int too large to convert to C numpy.intp"); + "Python int too large to convert to C numpy.intp"); return -1; } #endif @@ -849,13 +849,15 @@ PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals) */ nd = PySequence_Length(seq); if (nd == -1) { - if (PyErr_Occurred()) PyErr_Clear(); + if (PyErr_Occurred()) { + PyErr_Clear(); + } vals[0] = PyArray_PyIntAsIntp(seq); if(vals[0] == -1) { err = PyErr_Occurred(); - if (err && - PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { + if (err && + PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { PyErr_SetString(PyExc_ValueError, "Maximum allowed dimension exceeded"); } @@ -876,8 +878,8 @@ PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals) vals[i] = PyArray_PyIntAsIntp(op); if(vals[i] == -1) { err = PyErr_Occurred(); - if (err && - PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { + if (err && + PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { PyErr_SetString(PyExc_ValueError, "Maximum allowed dimension exceeded"); } @@ -892,13 +894,13 @@ PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals) /*NUMPY_API * PyArray_IntpFromSequence - * Returns the number of dimensions or -1 if an error occurred. + * Returns the number of integers converted or -1 if an error occurred. * vals must be large enough to hold maxvals */ NPY_NO_EXPORT int PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals) { - return (int)PyArray_IntpFromIndexSequence(seq, vals, (npy_intp)maxvals); + return PyArray_IntpFromIndexSequence(seq, vals, (npy_intp)maxvals); } diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index e993494ea167..2b9fcdb69714 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -6,13 +6,12 @@ from __future__ import division, absolute_import, print_function import sys - +import operator import warnings from nose.plugins.skip import SkipTest import numpy as np from numpy.testing import dec, run_module_suite, assert_raises -import operator class _DeprecationTestCase(object): diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index f8734ea5eeb3..c63f8140d080 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -830,5 +830,5 @@ def tile(A, reps): dim_in = shape[i] dim_out = dim_in*nrep shape[i] = dim_out - n //= max(dim_in,1) + n //= max(dim_in, 1) return c.reshape(shape) diff --git a/numpy/random/tests/test_regression.py b/numpy/random/tests/test_regression.py index 891345b6aca0..0edf580d20ba 100644 --- a/numpy/random/tests/test_regression.py +++ b/numpy/random/tests/test_regression.py @@ -74,7 +74,7 @@ def test_call_within_randomstate(self): np.random.seed(i) m.seed(4321) # If m.state is not honored, the result will change - assert_array_equal(m.choice(10, size=10, p=np.ones(10)/10), res) + assert_array_equal(m.choice(10, size=10, p=np.ones(10)/10.), res) if __name__ == "__main__": run_module_suite()