Skip to content

Commit

Permalink
STY: Style fixes for integer deprecation changes
Browse files Browse the repository at this point in the history
Also minor changes in the documentation.
  • Loading branch information
seberg committed Jun 9, 2013
1 parent 0e9dccd commit a6a2c60
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
22 changes: 12 additions & 10 deletions numpy/core/src/multiarray/conversion_utils.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -812,15 +812,15 @@ 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
#else
#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
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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);
}


Expand Down
3 changes: 1 addition & 2 deletions numpy/core/tests/test_deprecations.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/shape_base.py
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion numpy/random/tests/test_regression.py
Expand Up @@ -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()

0 comments on commit a6a2c60

Please sign in to comment.