diff options
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/multiarray/ctors.c | 3 | ||||
| -rw-r--r-- | numpy/core/tests/test_multiarray.py | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 60f76bf5e..e1989bab8 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -2940,7 +2940,8 @@ static int _safe_ceil_to_intp(double value, npy_intp* ret) double ivalue; ivalue = npy_ceil(value); - if (ivalue < NPY_MIN_INTP || ivalue > NPY_MAX_INTP) { + /* condition inverted to handle NaN */ + if (!(NPY_MIN_INTP <= ivalue && ivalue <= NPY_MAX_INTP)) { return -1; } diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 3bddfe2ae..f55bd0e2b 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -7270,6 +7270,10 @@ def test_npymath_real(): expected = npfun(z) assert_allclose(got, expected) +# Test when (stop - start) / step is NaN, ValueError is raised instead +# of returning a zero-length array. +def test_arange_nan(): + assert_raises(ValueError, np.arange, 0, 1, np.nan) if __name__ == "__main__": run_module_suite() |
