Skip to content

BUG: Fixed bug that Timedelta raises error when slicing from 0s (issue #10583) #10960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tseries/tests/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
3 changes: 1 addition & 2 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down