Alexander Belopolsky added the comment:

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 stats.py 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/statistics.py", line 387, in mean
    total = sum(data)
  File "/Users/sasha/Work/cpython-ro/Lib/statistics.py", 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/statistics.py", line 210, in sum
    raise TypeError('sum only accepts numbers')
TypeError: sum only accepts numbers

----------
nosy: +agthorr

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18606>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to