numpy/numpy — pull request #4542 by immerrr (2014-03-24 05:25:00+00:00)
Title: BUG: fix some errors raised when minlength is incorrect in np.bincount

I've encountered weird exceptions raised from `np.bincount` when `minlength` is incorrect. It turns out, `PyArray_PyIntAsIntp` return values were handled incorrectly in that function, this PR is an attempt to fix this.

I'd also argue that `minlength=0` is a valid input, but that would be an API change and hence worth a separate discussion.

## Before
```python
In [1]: np.bincount([1,2,3], minlength="foobar")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 np.bincount([1,2,3], minlength="foobar")

ValueError: minlength must be positive

In [2]: np.bincount([], minlength="foobar")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 np.bincount([], minlength="foobar")

ValueError: negative dimensions are not allowed

In [3]: np.bincount([], minlength=0)
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
in ()
----> 1 np.bincount([], minlength=0)

SystemError: error return without exception set

```

## After

```python

In [1]: np.bincount([1,2,3], minlength="foobar")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 np.bincount([1,2,3], minlength="foobar")

TypeError: an integer is required

In [2]: np.bincount([], minlength="foobar")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 np.bincount([], minlength="foobar")

TypeError: an integer is required

In [3]: np.bincount([], minlength=0)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 np.bincount([], minlength=0)

ValueError: minlength must be positive

```