Skip to content

ENH: implement TimedeltaArray/TimedeltaIIndex sum, median, std #28165

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 9 commits into from
Oct 8, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test for np.sum
  • Loading branch information
jbrockmendel committed Aug 27, 2019
commit ac16d03fa40e4e3443454dba71288197648097ea
14 changes: 14 additions & 0 deletions pandas/tests/arrays/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ def test_sum(self):
result = tdi.sum(skipna=False)
assert result is pd.NaT

def test_npsum(self):
# GH#25335 np.sum should return a Timedelta, not timedelta64
tdi = pd.TimedeltaIndex(["3H", "3H", "2H", "5H", "4H"])
arr = tdi._data

result = np.sum(tdi)
expected = pd.Timedelta(hours=17)
assert isinstance(result, pd.Timedelta)
assert result == expected

result = np.sum(arr)
assert isinstance(result, pd.Timedelta)
assert result == expected

def test_std(self):
tdi = pd.TimedeltaIndex(["0H", "4H", "NaT", "4H", "0H", "2H"])
arr = tdi._data
Expand Down