Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106445

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

From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: ANN: intervalset Was: Set type for datetime intervals
Date 2016-04-04 11:09 -0400
Message-ID <mailman.21.1459782605.32530.python-list@python.org> (permalink)
References <56FE0625.5030901@shopzeus.com> <1459523394.2611014.565840994.593DD99A@webmail.messagingengine.com> <570213CB.8040101@shopzeus.com> <1459782597.3444051.568344234.048046C6@webmail.messagingengine.com>

Show all headers | View raw


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 immutable versions.

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 only one interval and doing operations on that?

> I have some unit tests, but testers and comments are welcome.
> 
> Also see below.
> 
> Yes, you are right. It is a set of non-intersecting intervals.
> 
> > It could
> > also be useful to have one for numbers (the datetime version could even
> > maybe be implemented in terms of it)
> Well, please check sources on bitbucket. You are more than welcome to
> join the project.
> >
> >> element ::= (start_point_in_time, end_point_in_time)
> >> intervalset ::= { element1, element2, .... }
> > Are these open intervals or closed intervals?
> Closed. In my particular implementation, there is a singleton for all
> empty intervals. It is not possible to create an arbitrary interval with
> the same starting and ending time (the singleton being the only
> exception).

An "arbitrary interval with the same starting and ending time" would be
more like an isolated datetime (i.e. 00:00 is in the set but 23:59 or
00:01 is not)

> I think that implementing open intervals would be much more
> difficult, and we would have to know and use the smallest possible
> increment (resolution) of the date/time type. Which may be platform
> dependent.

My suggestion was to use boolean flags, and to use that to control
whether to use < or <= to test for membership.

An open interval is more like an hour where 00:00 is included and
00:59:59.999999 is included but 01:00 is not. With discrete resolution
it's as simple as just moving the endpoint off by one unit, but I think
it'd be cleaner to use flags (you'd need it for numeric intervals, since
numeric types can have any resolution).

>    def __contains__(self, other):
>        """Containment relation.
>
>        Tell if `other` is contained *completely* in this set. The argument can either be an Interval or an
>        IntervalSet.
>        """

I don't think this is appropriate for this operation; this should be
__gt__. __contains__ should test a datetime (or whatever type item), not
another Interval/IntervalSet.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: ANN: intervalset Was: Set type for datetime intervals Random832 <random832@fastmail.com> - 2016-04-04 11:09 -0400

csiph-web