-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
"IndexError: tuple index out of range" error with numpy array contain datetimes #15869
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
Comments
Interestingly, this works: pd.DataFrame(np.array([None, None, dt.now(), None])) But this does not: pd.DataFrame(np.array([None, None, None, dt.now(), None])) Numpy doesn't seem to handle the input arrays any differently, but [array([['NaT', 'NaT', '2017-04-04T13:54:03.236544000', 'NaT']], dtype='datetime64[ns]')] while the second is [array([None, None, None, datetime.datetime(2017, 4, 4, 13, 54, 10, 804563),
None], dtype=object)] I'm going to dig some more into this. |
@chrisaycock here's why. https://github.com/pandas-dev/pandas/blob/master/pandas/types/cast.py#L810 When we have a 1-d array that is
It might be better to simply modify These routines are robust to null values, check for the requested (datetime or timedelta-like), and don't read the entire routine if is just strings (which is the point here, we are trying to see w/o doing too much work if we can coerce this). This is called for every This may seem like overly paranoid / extreme. But remember we can actually have mixed dtypes that get coerced, e.g.:
but we need it be robust to non-matching types.
|
@jreback Agreed that the culprit is the "quick inference" on the first three elements. Is your proposal to modify The alternative is to |
i think maybe best way is to trash all of the logic for the sample and below then modify: is_possible_datetimelike_array to return 3 states (string is prob fine)
the u know if u should attempt to_datetime or to_timedelta or are done it short circuits so should be performant the issue is to try to not iterate (and convert) all strings |
@chrisaycock this was a can of worms, see #15892 |
Thanks for the quick fix guys |
Code Sample, a copy-pastable example if possible
Problem description
The above code works in an old version of pandas (0.7.3) but fails in the current version (0.19.2)
Expected Output
No error and dataframe containing the numpy date array
Output of
pd.show_versions()
pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 20.10.1
Cython: None
numpy: 1.12.1
scipy: None
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: