numpy/numpy — pull request #4219 by jgehrcke (2014-01-21 17:56:57+00:00)
Title: digitize: fix checking for zero length of `x` and `bins`.

In the current version of `digitize`, array length check and error message don't go together:

```python

>>> import numpy
>>> print "numpy version: ", numpy.__version__
numpy version: 1.8.0
>>> from numpy import digitize
>>> digitize(x=[], bins=[])
Traceback (most recent call last):
File "", line 1, in
ValueError: Both x and bins must have non-zero length
>>> digitize(x=[1], bins=[])
array([0])
```

In contrast to the error message `bins` of length 0 currently does not lead to an exception. I don't see why this should make sense. The current code (`if (lx <= 0 || lbins < 0)`) seems weird. I replaced it with `if (lx == 0 || lbins == 0)` (according to http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_SIZE), leading to expected behavior:

```python

>>> digitize(x=[], bins=[])
Traceback (most recent call last):
File "", line 1, in
ValueError: Both x and bins must have non-zero length
>>> digitize(x=[1], bins=[])
Traceback (most recent call last):
File "", line 1, in
ValueError: Both x and bins must have non-zero length
>>> digitize(x=[], bins=[1])
Traceback (most recent call last):
File "", line 1, in
ValueError: Both x and bins must have non-zero length
>>> digitize(x=[1], bins=[1])
array([1])
```