pydata/pandas — pull request #2804 by lesteve (2013-02-05 23:54:21+00:00)
Title: Creating DatetimeIndex from empty array with datetime64 dtype raises IndexError

using pandas from master:

```python
import numpy as np
import pandas as pd
pd.DatetimeIndex(np.array([], dtype='datetime64')
```

I get the following stack trace:

```python
/data/python/pandas/pandas/tseries/index.pyc in __new__(cls, data, freq, start, end, periods, copy, name, tz, verify_integrity, normalize, **kwds)
229 else:
230 if data.dtype != _NS_DTYPE:
--> 231 subarr = tslib.cast_to_nanoseconds(data)
232 else:
233 subarr = data

/data/python/pandas/pandas/tslib.so in pandas.tslib.cast_to_nanoseconds (pandas/tslib.c:14151)()

IndexError: invalid index
```

This happens because pandas.tslib.cast_to_nanoseconds expects the array to be not empty to get the datetime64 unit of the first element.

One way to fix it would be to check whether ```data``` is empty before trying the conversion.

It would be nice to have a better error inside ```pd.tslib.cast_to_nanoseconds``` saying that it expects a non-empty array as well.