[Python-Dev] datetime.timedelta total_microseconds

Wes Turner wes.turner at gmail.com
Thu Feb 28 14:52:33 EST 2019

You could specify the return value type annotations in the docstring of a
convert()/to_unit() method, or for each to_unit() method. Are they all

div and floordiv are not going away. Without reading the docs, I, too,
wouldn't have guessed that division by the desired unit is the correct way.

In terms of performance, a convert()/to_unit() method must do either a hash
lookup or multiple comparisons to present a more useful exception  than
that returned by initializing timedelta with something like nanoseconds=.

FWIW, astropy.time.TimeDelta supports sub-nanosecond precision and has a
.to() method for changing units/quantities.

> The TimeDelta class is derived from the Time class and shares many of its
properties. One difference is that the time scale has to be one for which
one day is exactly 86400 seconds. Hence, the scale cannot be UTC.
> The available time formats are:
> Format     Class
> sec            TimeDeltaSec
> jd              TimeDeltaJD
> datetime  TimeDeltaDatetime



On Thursday, February 28, 2019, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:

> > while "some_var / some_other_var" could be doing anything.
> "At an elementary level the division of two natural numbers is – among
> other possible interpretations – the process of calculating the number of
> times one number is contained within another one."
> -- <https://en.wikipedia.org/wiki/Division_(mathematics)>
> The process of figuring out how many seconds fit into a given interval is
> called division by a second.
> I am afraid people who get confused by timedelta / timedelta division know
> too much about Python where / can indeed mean anything including e.g.
> joining filesystem paths.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190228/82838ab3/attachment.html>

More information about the Python-Dev mailing list