This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients agthorr, belopolsky, christian.heimes, gregory.p.smith, pitrou, ronaldoussoren, steven.daprano, tshepang, vajrasky
Date 2013-08-04.02:07:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1375582078.36.0.764112705453.issue18606@psf.upfronthosting.co.za>
In-reply-to
Content
> Once we start special-casing types, where will it end?

At the point where all stdlib types are special-cased. :-)


> In the meantime, there's a simple way to do this:

py> from datetime import timedelta as td
py> data = [td(2), td(1), td(3), td(4)]
py> m = statistics.mean([x.total_seconds() for x in data])
py> td(seconds=m)
datetime.timedelta(2, 43200)

Simple, but as simple ways go in this area not correct.  Here is the right way:

py> td.resolution * statistics.mean(d//td.resolution for d in data)
datetime.timedelta(2, 43200)

I wish I had a solution to make sum() work properly on timedeltas without special-casing.  I thought that start could default to type(data[0])(0), but that would bring in strings.  Maybe statistics.mean() should support non-numbers that support addition and division by a number?  Will it be too confusing if mean() supports types that sum() does not?
History
Date User Action Args
2013-08-04 02:07:58belopolskysetrecipients: + belopolsky, gregory.p.smith, ronaldoussoren, pitrou, agthorr, christian.heimes, steven.daprano, tshepang, vajrasky
2013-08-04 02:07:58belopolskysetmessageid: <1375582078.36.0.764112705453.issue18606@psf.upfronthosting.co.za>
2013-08-04 02:07:58belopolskylinkissue18606 messages
2013-08-04 02:07:58belopolskycreate