From 82b87908cb26f71286c8deb367570b055b4c9b05 Mon Sep 17 00:00:00 2001 From: terrytangyuan Date: Tue, 1 Sep 2015 08:45:06 -0400 Subject: [PATCH] BUG: Fixed bug that Timedelta raises error when slicing from 0s --- doc/source/whatsnew/v0.17.0.txt | 1 + pandas/tseries/tests/test_timedeltas.py | 8 ++++++++ pandas/tslib.pyx | 3 +-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index eae33bc80be32..fc5777ddea3f1 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -821,6 +821,7 @@ Bug Fixes - Bug in ``pd.DataFrame`` when constructing an empty DataFrame with a string dtype (:issue:`9428`) - Bug in ``pd.DataFrame.diff`` when DataFrame is not consolidated (:issue:`10907`) - 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`) +- Bug in ``Timedelta`` raising error when slicing from 0s (:issue:`10583`) - Bug in ``DatetimeIndex.take`` and ``TimedeltaIndex.take`` may not raise ``IndexError`` against invalid index (:issue:`10295`) - Bug in ``Series([np.nan]).astype('M8[ms]')``, which now returns ``Series([pd.NaT])`` (:issue:`10747`) - Bug in ``PeriodIndex.order`` reset freq (:issue:`10295`) diff --git a/pandas/tseries/tests/test_timedeltas.py b/pandas/tseries/tests/test_timedeltas.py index 4870fbd55f33e..97e7f883542cc 100644 --- a/pandas/tseries/tests/test_timedeltas.py +++ b/pandas/tseries/tests/test_timedeltas.py @@ -404,6 +404,14 @@ def test_timedelta_range(self): result = timedelta_range('0 days',freq='30T',periods=50) tm.assert_index_equal(result, expected) + # issue10583 + df = pd.DataFrame(np.random.normal(size=(10,4))) + df.index = pd.timedelta_range(start='0s', periods=10, freq='s') + expected = df.loc[pd.Timedelta('0s'):,:] + result = df.loc['0s':,:] + assert_frame_equal(expected, result) + + def test_numeric_conversions(self): self.assertEqual(ct(0), np.timedelta64(0,'ns')) self.assertEqual(ct(10), np.timedelta64(10,'ns')) diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index 369993b4c54d1..77ac362181a2b 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -2265,9 +2265,8 @@ class Timedelta(_Timedelta): return "m" elif self._h: return "h" - elif self._d: + else: return "D" - raise ValueError("invalid resolution") def round(self, reso): """