-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
Slicing a TimeSeries object with a PeriodIndex fails with an index out of bounds error
Example
dates = pd.period_range(start='01-Apr-11',end='31-Mar-12 23:00',freq='h')
ts = pd.TimeSeries(0,dates)
ts[ts.index[4:10]]
Traceback (most recent call last):
File "", line 3, in
ts[ts.index[4:10]]
File "C:\dev\bin\Python27\lib\site-packages\pandas\core\series.py", line 506, in getitem
return self._get_with(key)
File "C:\dev\bin\Python27\lib\site-packages\pandas\core\series.py", line 544, in _get_with
return self._get_values(key)
File "C:\dev\bin\Python27\lib\site-packages\pandas\core\series.py", line 575, in _get_values
return self.values[indexer]
IndexError: index 361564 out of bounds 0<=index<8784
It appears the PeriodIndex is being inferred as 'integer' in series._get_with() using lib.infer_dtype() whereas self.index.inferred_type returns 'period'
if isinstance(key, Index):
key_type = lib.infer_dtype(key.values)
else:
key_type = lib.infer_dtype(key)
if key_type == 'integer':
if self.index.inferred_type == 'integer':
return self.reindex(key)
else:
return self._get_values(key)
elif key_type == 'boolean':
return self._get_values(key)