You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [1]: importpandasaspdIn [2]: importnumpyasnpIn [3]: s=pd.Series(range(11), pd.timedelta_range('0 days', '10 days'))
In [4]: sOut[4]:
0days01days12days23days34days45days56days67days78days89days910days10Freq: D, dtype: int64In [5]: s.loc[np.timedelta64(0, 'ns'):]
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
<ipython-input-5-44a523c6460e>in<module>()
---->1s.loc[np.timedelta64(0, 'ns'):]
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexing.pyin__getitem__(self, key)
13711372maybe_callable=com._apply_if_callable(key, self.obj)
->1373returnself._getitem_axis(maybe_callable, axis=axis)
13741375def_is_scalar_access(self, key):
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexing.pyin_getitem_axis(self, key, axis)
1579ifisinstance(key, slice):
1580self._has_valid_type(key, axis)
->1581returnself._get_slice_axis(key, axis=axis)
1582elifis_bool_indexer(key):
1583returnself._getbool_axis(key, axis=axis)
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexing.pyin_get_slice_axis(self, slice_obj, axis)
1404labels=obj._get_axis(axis)
1405indexer=labels.slice_indexer(slice_obj.start, slice_obj.stop,
->1406slice_obj.step, kind=self.name)
14071408ifisinstance(indexer, slice):
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexes/base.pyinslice_indexer(self, start, end, step, kind)
3455 """
3456 start_slice, end_slice = self.slice_locs(start, end, step=step,
-> 3457 kind=kind)
3458
3459 # return a slice
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexes/base.py in slice_locs(self, start, end, step, kind)
3656 start_slice = None
3657 if start is not None:
-> 3658 start_slice = self.get_slice_bound(start, 'left', kind)
3659 if start_slice is None:
3660 start_slice = 0
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_slice_bound(self, label, side, kind)
3582 # For datetime indices label may be a string that has to be converted
3583 # to datetime boundary according to its resolution.
-> 3584 label = self._maybe_cast_slice_bound(label, side, kind)
3585
3586 # we need to look up the label
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexes/timedeltas.py in _maybe_cast_slice_bound(self, label, side, kind)
739 Timedelta(1, 'ns'))
740 elif is_integer(label) or is_float(label):
--> 741 self._invalid_indexer('slice', label)
742
743 return label
~/miniconda3/envs/xarray-py36/lib/python3.6/site-packages/pandas/core/indexes/base.py in _invalid_indexer(self, form, key)
1574 "indexers [{key}] of {kind}".format(
1575 form=form, klass=type(self), key=key,
-> 1576 kind=type(key)))
1577
1578 def get_duplicates(self):
TypeError: cannot do slice indexing on <class 'pandas.core.indexes.timedeltas.TimedeltaIndex'> with these indexers [0] of <class 'numpy.timedelta64'>
Problem description
I expect this to work as if I did indexing with a pd.Timedelta object:
In [6]: s.loc[pd.Timedelta('0 days'):]
Out[6]:
0 days 0
1 days 1
2 days 2
3 days 3
4 days 4
5 days 5
6 days 6
7 days 7
8 days 8
9 days 9
10 days 10
Freq: D, dtype: int64
This was surprising because every other pandas index can be indexed by the corresponding pandas scalar type. For example, this works with DatetimeIndex:
Code Sample, a copy-pastable example if possible
Problem description
I expect this to work as if I did indexing with a
pd.Timedelta
object:This was surprising because every other pandas index can be indexed by the corresponding pandas scalar type. For example, this works with DatetimeIndex:
Expected Output
Output of
pd.show_versions()
pandas: 0.22.0
pytest: 3.4.0
pip: 9.0.1
setuptools: 38.5.1
Cython: None
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: 0.10.2
IPython: 6.2.1
sphinx: 1.7.0
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: