Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-28 Thread Wes Turner
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 floats? 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

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-28 Thread Alexander Belopolsky
> 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." --

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-28 Thread INADA Naoki
> > I *think* this is the "correct" way to do it: > > def timedelta_to_microseconds(td): > return td.microseconds + td.seconds * 1000 + td.days * 8640 > > (hardly tested) > > -CHB > 1000? milli? micro? -- INADA Naoki ___ Python-Dev mailing

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-27 Thread Chris Barker via Python-Dev
On Wed, Feb 27, 2019 at 3:04 PM Richard Belleville wrote: > Timedelta division is quite a nice solution to the problem. However, since > we're maintaining a python version agnostic library at least until 2020, we > need a solution that works in python 2 as well. > So you were limited to a py2 so

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-27 Thread Richard Belleville via Python-Dev
Sorry for the slow response. Timedelta division is quite a nice solution to the problem. However, since we're maintaining a python version agnostic library at least until 2020, we need a solution that works in python 2 as well. For the moment, we've left the code as in the original snippet. Rich

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-27 Thread Chris Barker via Python-Dev
Did we ever hear back from the OP as to whether they were using py2 or 3? If they were unable to find timedelta division in py3 -- that's a pretty good case that we need something else. The OP: """ On Wed, Feb 13, 2019 at 9:10 PM Richard Belleville via Python-Dev < python-dev@python.org> wrote:

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-27 Thread Chris Barker via Python-Dev
On Wed, Feb 27, 2019 at 7:15 AM Paul Ganssle wrote: > As another data point, I also have a background in the physical sciences, > and I actually do find it quite intuitive. The first time I saw this idiom > I took it to heart immediately and only stopped using it because many of > the libraries I

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-27 Thread Chris Barker via Python-Dev
On Tue, Feb 26, 2019 at 7:22 PM Terry Reedy wrote: > > timedelta.total_seconds() > > To me, total_x implies that there is a summation of multiple timedeltas, > and there is not. So not intuitive to me. THAT was a discussion for when it was added -- I can't say it's my favorite name either. But

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-27 Thread Steve Holden
We should also consider that before long datetimes are frequently stored to nanosecond resolution (two fields where this is significant are finance and physics, and the latter would probably appreciate femtosedonds as well). So maybe an external library that layers on top of datetime might be prefe

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-27 Thread Paul Ganssle
On 2/26/19 7:03 PM, Chris Barker via Python-Dev wrote: > This thread petered out, seemingly with a consensus that we should > update the docs -- is anyone doing that? > I don't think anyone is, I've filed a BPO bug for it: https://bugs.python.org/issue3613 > > -- I am a physical scientist, I work

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-26 Thread Fred Drake
On Tue, Feb 26, 2019 at 10:20 PM Terry Reedy wrote: > To me, total_x implies that there is a summation of multiple timedeltas, > and there is not. Do you believe this is a particularly dominant perception? I don't, but specific backgrounds probably play into this heavily. I'd expect to total a

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-26 Thread Terry Reedy
On 2/26/2019 7:03 PM, Chris Barker via Python-Dev wrote: So: it would be good to provide a correct, simple,  intuitive, and discoverable way to do that. timedelta.total_seconds() To me, total_x implies that there is a summation of multiple timedeltas, and there is not. So not intuitive to

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-26 Thread Chris Barker via Python-Dev
This thread petered out, seemingly with a consensus that we should update the docs -- is anyone doing that? But anyway, I'd like to offer a counterpoint: >From the OP, it is clear that: * Folks have a need for timedeltas to be converted to numbers values, with units other than seconds (milliseco

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-20 Thread Alexander Belopolsky
On Fri, Feb 15, 2019 at 5:29 PM Paul Ganssle wrote: > it allows you to use non-traditional units like weeks (timedelta(days=7)) > Weeks are traditional: >>> timedelta(weeks=1) datetime.timedelta(7) :-) ___ Python-Dev mailing list Python-Dev@python.o

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-16 Thread Henry Chen
+1 on the improved docs solution: no new code to maintain and big return on investment in preventing future bugs / confusion :) On Sat, Feb 16, 2019 at 9:40 AM Nick Coghlan wrote: > On Sun, 17 Feb 2019 at 03:20, Paul Ganssle wrote: > > I think if we add such a function, it will essentially be j

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-16 Thread Nick Coghlan
On Sun, 17 Feb 2019 at 03:20, Paul Ganssle wrote: > I think if we add such a function, it will essentially be just a slower > version of something that already exists. I suspect the main reason the > "divide the timedelta by the interval" thing isn't a common enough idiom that > people see it a

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-16 Thread Paul Ganssle
I am definitely sympathetic to the idea of it being more readable, but I feel like this adds some unnecessary bloat to the interface when "divide the value by the units" is not at all uncommon. Plus, if you add a total_duration that by default does the same thing as total_seconds, you now have thre

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-16 Thread Nick Coghlan
On Fri, 15 Feb 2019 at 04:15, Alexander Belopolsky wrote: > > > > On Thu, Feb 14, 2019 at 9:07 AM Paul Ganssle wrote: >> >> I don't think it's totally unreasonable to have other total_X() methods, >> where X would be days, hours, minutes and microseconds > > I do. I was against adding the total

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-15 Thread Henry Chen
Indeed there is a potential loss of precision: _timedelta_to_microseconds(timedelta(0, 1, 1)) returns 100 where conversion function is defined according to the initial message in this thread On Fri, Feb 15, 2019 at 2:29 PM Paul Ganssle wrote: > I'm still with Alexander on this. I see funct

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-15 Thread Paul Ganssle
I'm still with Alexander on this. I see functions like total_X as basically putting one of the arguments directly in the function name - it should be `total_duration(units)`, not `total_units()`, because all of those functions do the same thing and only differ in the units they use. But Alexander'

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-15 Thread Chris Barker via Python-Dev
On Fri, Feb 15, 2019 at 11:58 AM Rob Cliffe via Python-Dev < python-dev@python.org> wrote: > A function with "microseconds" in the name IMO misleadingly suggests that > it has something closer to microsecond accuracy than a 1-second granularity. > it sure does, but `delta.total_seconds()` is a fl

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-15 Thread Rob Cliffe via Python-Dev
A function with "microseconds" in the name IMO misleadingly suggests that it has something closer to microsecond accuracy than a 1-second granularity. Rob Cliffe On 14/02/2019 05:05:54, Richard Belleville via Python-Dev wrote: In a recent code review, the following snippet was called out as re

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-14 Thread Paul Ganssle
Ah yes, good point, I forgot about this because IIRC it's not supported in Python 2.7, so it's not a particularly common idiom in polyglot library code. Obviously any new methods would be Python 3-only, so there's no benefit to adding them. Best, Paul On 2/14/19 1:12 PM, Alexander Belopolsky wr

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-14 Thread Alexander Belopolsky
On Thu, Feb 14, 2019 at 9:07 AM Paul Ganssle wrote: > I don't think it's totally unreasonable to have other total_X() methods, > where X would be days, hours, minutes and microseconds > I do. I was against adding the total_seconds() method to begin with because the same effect can be achieved wi

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-14 Thread Paul Ganssle
I don't think it's totally unreasonable to have other total_X() methods, where X would be days, hours, minutes and microseconds, but it also doesn't seem like a pressing need to me. I think the biggest argument against it is that they are all trivial to implement as necessary, because they're just

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-13 Thread Henry Chen
Oops. That isn't the TOTAL microseconds, but just the microseconds portion. Sorry for the confusion. On Wed, Feb 13, 2019 at 9:23 PM Henry Chen wrote: > Looks like timedelta has a microseconds property. Would this work for your > needs? > > In [12]: d > Out[12]: datetime.timedelta(0, 3, 398407)

Re: [Python-Dev] datetime.timedelta total_microseconds

2019-02-13 Thread Henry Chen
Looks like timedelta has a microseconds property. Would this work for your needs? In [12]: d Out[12]: datetime.timedelta(0, 3, 398407) In [13]: d.microseconds Out[13]: 398407 On Wed, Feb 13, 2019 at 9:08 PM Richard Belleville via Python-Dev < python-dev@python.org> wrote: > In a recent code rev

[Python-Dev] datetime.timedelta total_microseconds

2019-02-13 Thread Richard Belleville via Python-Dev
In a recent code review, the following snippet was called out as reinventing the wheel: _MICROSECONDS_PER_SECOND = 100 def _timedelta_to_microseconds(delta): return int(delta.total_seconds() * _MICROSECONDS_PER_SECOND) The reviewer thought that there must already exist a standard library