Changeset 8084

Show
Ignore:
Timestamp:
02/01/10 22:54:53 (7 months ago)
Author:
cdavid
Message:

BUG: fix #1387. Raise ValueError? for empty input to bincount.

Location:
trunk/numpy/lib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/numpy/lib/src/_compiled_base.c

    r7911 r8084  
    118118    } 
    119119    len = PyArray_SIZE(lst); 
     120    if (len < 1) { 
     121        PyErr_SetString(PyExc_ValueError, 
     122                "The first argument cannot be empty."); 
     123        goto fail; 
     124    } 
    120125    numbers = (intp *) PyArray_DATA(lst); 
    121126    mxi = mxx(numbers, len); 
  • trunk/numpy/lib/tests/test_regression.py

    r7509 r8084  
    177177            raise AssertionError("ticket #1243") 
    178178 
     179    def test_bincount_empty(self): 
     180        """Ticket #1387: empty array as input for bincount.""" 
     181        assert_raises(ValueError, lambda : np.bincount(np.array([], dtype=np.intp))) 
    179182 
    180183if __name__ == "__main__":