Author belopolsky
Recipients agthorr, belopolsky, gregory.p.smith, pitrou, ronaldoussoren, steven.daprano, tshepang, vajrasky
Date 2013-08-03.19:31:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Here is the use-case that was presented to support adding additional operations on timedelta objects:

I'm conducting a series of observation experiments where I
measure the duration of an event.  I then want to do various
statistical analysis such as computing the mean, median,
etc.  Originally, I tried using standard functions such as
lmean from the package.  However, these sorts of
functions divide by a float at the end, causing them to fail
on timedelta objects.  Thus, I have to either write my own
special functions, or convert the timedelta objects to
integers first (then convert them back afterwards).
"""  (Daniel Stutzbach, in msg26267 on issue1289118.)

The proposed statistics module does not support this use case:

>>> mean([timedelta(1)])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sasha/Work/cpython-ro/Lib/", line 387, in mean
    total = sum(data)
  File "/Users/sasha/Work/cpython-ro/Lib/", line 223, in sum
    total += x
TypeError: unsupported operand type(s) for +=: 'int' and 'datetime.timedelta'
>>> sum([timedelta(1)], timedelta(0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sasha/Work/cpython-ro/Lib/", line 210, in sum
    raise TypeError('sum only accepts numbers')
TypeError: sum only accepts numbers
Date User Action Args
2013-08-03 19:31:26belopolskysetrecipients: + belopolsky, gregory.p.smith, ronaldoussoren, pitrou, agthorr, steven.daprano, tshepang, vajrasky
2013-08-03 19:31:26belopolskysetmessageid: <>
2013-08-03 19:31:26belopolskylinkissue18606 messages
2013-08-03 19:31:25belopolskycreate