Skip to content

Conversation

lesteve
Copy link
Contributor

@lesteve lesteve commented Feb 5, 2013

using pandas from master:

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

I get the following stack trace:

/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.

wesm added a commit that referenced this pull request Feb 10, 2013
@wesm
Copy link
Member

wesm commented Feb 10, 2013

thanks!

@wesm wesm closed this Feb 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants