unstack with DatetimeIndex with NaN gives "ValueError: cannot convert float NaN to integer" · Issue #7401 · pandas-dev/pandas (original) (raw)
With following code:
df = pd.DataFrame({'A': list('aaaaabbbbb'),
'B':pd.date_range('2012-01-01', periods=5).tolist()*2,
'C':np.zeros(10)})
df.iloc[3,1] = np.NaN
df = df.set_index(['A', 'B'])
unstacking gives:
In [6]: df.unstack()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-9a91d46cdd8d> in <module>()
----> 1 df.unstack()
...
c:\users\vdbosscj\scipy\pandas-joris\pandas\tseries\index.pyc in _simple_new(cls
, values, name, freq, tz)
461 def _simple_new(cls, values, name, freq=None, tz=None):
462 if values.dtype != _NS_DTYPE:
--> 463 values = com._ensure_int64(values).view(_NS_DTYPE)
464
465 result = values.view(cls)
c:\users\vdbosscj\scipy\pandas-joris\pandas\algos.pyd in pandas.algos.ensure_int
64 (pandas\algos.c:47444)()
c:\users\vdbosscj\scipy\pandas-joris\pandas\algos.pyd in pandas.algos.ensure_int
64 (pandas\algos.c:47349)()
ValueError: cannot convert float NaN to integer
I don't know if this should work (unstacking with NaN in the index), but at least this is not a very clear error message to know what could be going wrong.