Skip to content

Commit 9bdae60

Browse files
committed
Merge pull request #10960 from terrytangyuan/PR2update
BUG: Fixed bug that Timedelta raises error when slicing from 0s (issue #10583)
2 parents f784e9a + 82b8790 commit 9bdae60

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

doc/source/whatsnew/v0.17.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ Bug Fixes
822822
- Bug in ``pd.DataFrame`` when constructing an empty DataFrame with a string dtype (:issue:`9428`)
823823
- Bug in ``pd.DataFrame.diff`` when DataFrame is not consolidated (:issue:`10907`)
824824
- Bug in ``pd.unique`` for arrays with the ``datetime64`` or ``timedelta64`` dtype that meant an array with object dtype was returned instead the original dtype (:issue:`9431`)
825+
- Bug in ``Timedelta`` raising error when slicing from 0s (:issue:`10583`)
825826
- Bug in ``DatetimeIndex.take`` and ``TimedeltaIndex.take`` may not raise ``IndexError`` against invalid index (:issue:`10295`)
826827
- Bug in ``Series([np.nan]).astype('M8[ms]')``, which now returns ``Series([pd.NaT])`` (:issue:`10747`)
827828
- Bug in ``PeriodIndex.order`` reset freq (:issue:`10295`)

pandas/tseries/tests/test_timedeltas.py

+8
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ def test_timedelta_range(self):
404404
result = timedelta_range('0 days',freq='30T',periods=50)
405405
tm.assert_index_equal(result, expected)
406406

407+
# issue10583
408+
df = pd.DataFrame(np.random.normal(size=(10,4)))
409+
df.index = pd.timedelta_range(start='0s', periods=10, freq='s')
410+
expected = df.loc[pd.Timedelta('0s'):,:]
411+
result = df.loc['0s':,:]
412+
assert_frame_equal(expected, result)
413+
414+
407415
def test_numeric_conversions(self):
408416
self.assertEqual(ct(0), np.timedelta64(0,'ns'))
409417
self.assertEqual(ct(10), np.timedelta64(10,'ns'))

pandas/tslib.pyx

+1-2
Original file line numberDiff line numberDiff line change
@@ -2265,9 +2265,8 @@ class Timedelta(_Timedelta):
22652265
return "m"
22662266
elif self._h:
22672267
return "h"
2268-
elif self._d:
2268+
else:
22692269
return "D"
2270-
raise ValueError("invalid resolution")
22712270

22722271
def round(self, reso):
22732272
"""

0 commit comments

Comments
 (0)