Skip to content

Creating DatetimeIndex from empty array with datetime64 dtype raises IndexError #2804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down