[New-bugs-announce] [issue8860] Rounding in timedelta constructor is inconsistent with that in timedelta arithmetics

Alexander Belopolsky report at bugs.python.org
Mon May 31 18:39:41 CEST 2010


New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:

>From issue1289118, msg106389:

"""
>>> from datetime import timedelta as d
>>> [d(microseconds=i + .5)//d.resolution for i in range(-10,10)]
[-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Should this be considered a bug?

For comparison,

>>> [d.resolution*(i+0.5)//d.resolution for i in range(-10,10)]
[-10, -8, -8, -6, -6, -4, -4, -2, -2, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10]

and
>>> [round(i+0.5) for i in range(-10,10)]
[-10, -8, -8, -6, -6, -4, -4, -2, -2, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10]

I checked the documentation and while it says: "If any argument is a float and there are fractional microseconds, the fractional microseconds left over from all arguments are combined and their sum is rounded to the nearest microsecond." it does not specify how half-integers should be handled.

While it may not be a bug in strict sense, it looks like the code in question can be improved. 
"""

----------
assignee: belopolsky
messages: 106793
nosy: belopolsky, haypo, mark.dickinson, mcherm, rhettinger, stutzbach, tim_one
priority: normal
severity: normal
stage: unit test needed
status: open
title: Rounding in timedelta constructor is inconsistent with that in timedelta arithmetics
type: feature request

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8860>
_______________________________________


More information about the New-bugs-announce mailing list