Re: Set type for datetime intervals

2016-04-06 Thread Martin A. Brown
>> Sorry to be late to the party--I applaud that you have already >> crafted something to attack your problem. When you first posted, >> there was a library that was tickling my memory, but I could not >> remember its (simple) name. It occurred to me this morning, after >> you posted your

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-06 Thread Random832
On Tue, Apr 5, 2016, at 17:37, Nagy László Zsolt wrote: > > >> It is blurred by design. There is an interpretation where an interval > >> between [0..4] equals to a set of intervals ([0..2],[2..4]). > > No, because 2.5 is in one and not the other. > My notation was: 0..4 for any number between 0

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-06 Thread Michael Selik
On Tue, Apr 5, 2016, 10:46 PM Nagy László Zsolt wrote: > > >> How about creating two classes for this? One that supports zero sized > >> intervals, and another that doesn't? > > If you don't want zero sized intervals, just don't put any in it. You > > don't have a separate

Re: Set type for datetime intervals

2016-04-06 Thread Nagy László Zsolt
> Sorry to be late to the party--I applaud that you have already > crafted something to attack your problem. When you first posted, > there was a library that was tickling my memory, but I could not > remember its (simple) name. It occurred to me this morning, after > you posted your new

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Nagy László Zsolt
>> How about creating two classes for this? One that supports zero sized >> intervals, and another that doesn't? > If you don't want zero sized intervals, just don't put any in it. You > don't have a separate list type to support even integers vs one that > supports all floats. What operations

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Nagy László Zsolt
>> It is blurred by design. There is an interpretation where an interval >> between [0..4] equals to a set of intervals ([0..2],[2..4]). > No, because 2.5 is in one and not the other. My notation was: 0..4 for any number between 0 and 4. And 2..4 for any number between 2 and 4. So yes, 2.5 is in

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Michael Selik
It seems coding a generic interval and intervalset will bring a variety of difficult design choices. If I were you, I'd forget making it generic and build one specifically for the application you have in mind. That way you can ignore most of these feature discussions. > On Apr 5, 2016, at 2:59

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Random832
On Tue, Apr 5, 2016, at 04:11, Nagy László Zsolt wrote: > But there is still need to check begin <= end. But maybe > you are right: if we suppose that nobody will try to use an interval > where end < begin then we can use plain tuples. But then the user *must* > make sure not to use invalid

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Random832
On Tue, Apr 5, 2016, at 01:44, Nagy László Zsolt wrote: > If you want to manipulate an interval set, you cannot just "add another > interval" to it. Adding an interval may result in unifying thousands of > other intervals. It is possible that you add a wide interval to a set > with 1000 elements,

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Nagy László Zsolt
> Yes, my question is why it's useful to have a single Interval as a > *distinct* type, separate from the interval set type, which supports a > sharply limited number of set-like operations (such as the union of two > overlapping intervals but NOT two non-overlapping ones). This doesn't > appear

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt
> I don't know if I like it being immutable. Maybe have separate mutable > and immutable versions. The reason for making it immutable is implementation specific. These intervals are stored in an ordered list. Overlapping intervals are unified by the constructor. This makes sure that sets with

Re: Set type for datetime intervals

2016-04-04 Thread Martin A. Brown
Greetings László, >I need to compare sets of datetime intervals, and make set >operations on them: intersect, union, difference etc. One element >of a set would be an interval like this: > >element ::= (start_point_in_time, end_point_in_time) >intervalset ::= { element1, element2, } >

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Random832
On Mon, Apr 4, 2016, at 11:32, Oscar Benjamin wrote: > On 4 April 2016 at 16:09, Random832 wrote: > > Like I said before, I don't think the set-like operations on Intervals > > are useful - what can you accomplish with them rather than by making a > > set consisting of

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Oscar Benjamin
On 4 April 2016 at 16:09, Random832 wrote: > On Mon, Apr 4, 2016, at 03:12, Nagy László Zsolt wrote: >> >> Hi All, >> >> If anyone is interested, a module was born: >> >> https://bitbucket.org/nagylzs/intervalset >> https://pypi.python.org/pypi/intervalset/0.1.1 > > I

Re: Set type for datetime intervals

2016-04-04 Thread Random832
On Mon, Apr 4, 2016, at 06:15, Nagy László Zsolt wrote: > If you define the intersection operation on interval sets only, then you > need to write something like this: > > if IntervalSet(i1)*IntervalSet(i2): > pass > > which is both uglier and an overkill. I guess what I don't understand in

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Random832
On Mon, Apr 4, 2016, at 03:12, Nagy László Zsolt wrote: > > Hi All, > > If anyone is interested, a module was born: > > https://bitbucket.org/nagylzs/intervalset > https://pypi.python.org/pypi/intervalset/0.1.1 I don't know if I like it being immutable. Maybe have separate mutable and

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt
> Why do you limit the intervals to datetime? Are there any assumptions in > your code that would make it fail with int values? It has been generalized. Now it can be used with any immutable ordered type. :-) -- https://mail.python.org/mailman/listinfo/python-list

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt
> Why do you limit the intervals to datetime? Are there any assumptions in > your code that would make it fail with int values? Just one. The empty interval is a singleton and I want it to be smaller than any other interval. UTC_ZERO = datetime.datetime.utcfromtimestamp(0) EMPTY_INTERVAL =

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Peter Otten
Nagy László Zsolt wrote: > If anyone is interested, a module was born: > > https://bitbucket.org/nagylzs/intervalset > https://pypi.python.org/pypi/intervalset/0.1.1 > > I have some unit tests, but testers and comments are welcome. Why do you limit the intervals to datetime? Are there any

Re: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt
>> element ::= (start_point_in_time, end_point_in_time) >> intervalset ::= { element1, element2, } >> >> Operations on elements: > > Eh... I think these should be realized as operations on an intervalset > with a single element, and that elements should simply have properties > like the

Re: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt
> > On Fri, Apr 1, 2016 at 1:32 AM Nagy László Zsolt > wrote: > > Does anyone know a library that already implements these functions? > > > What do you not like about the ones on PyPI? >

ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt
Hi All, If anyone is interested, a module was born: https://bitbucket.org/nagylzs/intervalset https://pypi.python.org/pypi/intervalset/0.1.1 I have some unit tests, but testers and comments are welcome. Also see below. >> >> Hello, >> >> I need to compare sets of datetime intervals,

Re: Set type for datetime intervals

2016-04-01 Thread Michael Selik
Whoops, I mixed up tasks. Here's what I meant: def interval(start, stop, precision=60): a, b = start.timestamp(), stop.timestamp() return set(range(a, b, precision)) On Fri, Apr 1, 2016 at 4:31 PM Michael Selik wrote: > On Fri, Apr 1, 2016 at 1:32

Re: Set type for datetime intervals

2016-04-01 Thread Michael Selik
On Fri, Apr 1, 2016 at 1:32 AM Nagy László Zsolt wrote: > Does anyone know a library that already implements these functions? > What do you not like about the ones on PyPI? https://pypi.python.org/pypi?%3Aaction=search=interval=search Depending on the resolution you want,

Re: Set type for datetime intervals

2016-04-01 Thread Random832
More thoughts... sorry. On Fri, Apr 1, 2016, at 01:24, Nagy László Zsolt wrote: > > Hello, > > I need to compare sets of datetime intervals, and make set operations on > them: intersect, union, difference etc. One element of a set would be an > interval like this: > > element ::=

Re: Set type for datetime intervals

2016-04-01 Thread Random832
On Fri, Apr 1, 2016, at 01:24, Nagy László Zsolt wrote: > > Hello, > > I need to compare sets of datetime intervals, and make set operations on > them: intersect, union, difference etc. One element of a set would be an > interval like this: Two thoughts on this: Such an object is not

Set type for datetime intervals

2016-03-31 Thread Nagy László Zsolt
Hello, I need to compare sets of datetime intervals, and make set operations on them: intersect, union, difference etc. One element of a set would be an interval like this: element ::= (start_point_in_time, end_point_in_time) intervalset ::= { element1, element2, } Operations on