diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 5b1d6c31403cb..40fc2e702402a 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -106,6 +106,10 @@ def test_isnull_datetime(): assert(mask[0]) assert(not mask[1:].any()) +def test_datetimeindex_from_empty_datetime64_array(): + for unit in [ 'ms', 'us', 'ns' ]: + idx = DatetimeIndex(np.array([], dtype='datetime64[%s]' % unit)) + assert(len(idx) == 0) def test_any_none(): assert(com._any_none(1, 2, 3, None)) diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py index e45c21084e45f..04d19842ee846 100644 --- a/pandas/tseries/index.py +++ b/pandas/tseries/index.py @@ -227,7 +227,7 @@ def __new__(cls, data=None, offset = data.offset verify_integrity = False else: - if data.dtype != _NS_DTYPE: + if data.dtype != _NS_DTYPE and data.size: subarr = tslib.cast_to_nanoseconds(data) else: subarr = data