diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/add_newdocs.py | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/compiled_base.c | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 15 |
3 files changed, 10 insertions, 11 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index cf4af9f84..40b38e01a 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -5107,7 +5107,7 @@ add_newdoc('numpy.core.multiarray', 'digitize', add_newdoc('numpy.core.multiarray', 'bincount', """ - bincount(x, weights=None, minlength=None) + bincount(x, weights=None, minlength=0) Count number of occurrences of each value in array of non-negative ints. diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c index 7ff803f96..2d84db85b 100644 --- a/numpy/core/src/multiarray/compiled_base.c +++ b/numpy/core/src/multiarray/compiled_base.c @@ -117,10 +117,10 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds) } else { minlength = PyArray_PyIntAsIntp(mlength); - if (minlength <= 0) { + if (minlength < 0) { if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ValueError, - "minlength must be positive"); + "minlength must be non-negative"); } goto fail; } diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 188c1c2ea..708b20482 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2507,11 +2507,16 @@ class TestBincount(TestCase): x = np.array([0, 1, 0, 1, 1]) y = np.bincount(x, minlength=3) assert_array_equal(y, np.array([2, 3, 0])) + x = [] + y = np.bincount(x, minlength=0) + assert_array_equal(y, np.array([])) def test_with_minlength_smaller_than_maxvalue(self): x = np.array([0, 1, 1, 2, 2, 3, 3]) y = np.bincount(x, minlength=2) assert_array_equal(y, np.array([1, 2, 2, 2])) + y = np.bincount(x, minlength=0) + assert_array_equal(y, np.array([1, 2, 2, 2])) def test_with_minlength_and_weights(self): x = np.array([1, 2, 4, 5, 2]) @@ -2535,22 +2540,16 @@ class TestBincount(TestCase): "'str' object cannot be interpreted", lambda: np.bincount(x, minlength="foobar")) assert_raises_regex(ValueError, - "must be positive", + "must be non-negative", lambda: np.bincount(x, minlength=-1)) - assert_raises_regex(ValueError, - "must be positive", - lambda: np.bincount(x, minlength=0)) x = np.arange(5) assert_raises_regex(TypeError, "'str' object cannot be interpreted", lambda: np.bincount(x, minlength="foobar")) assert_raises_regex(ValueError, - "minlength must be positive", + "minlength must be non-negative", lambda: np.bincount(x, minlength=-1)) - assert_raises_regex(ValueError, - "minlength must be positive", - lambda: np.bincount(x, minlength=0)) @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") def test_dtype_reference_leaks(self): |