Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: ANN: intervalset Was: Set type for datetime intervals Date: Mon, 04 Apr 2016 11:09:57 -0400 Lines: 65 Message-ID: References: <56FE0625.5030901@shopzeus.com> <1459523394.2611014.565840994.593DD99A@webmail.messagingengine.com> <570213CB.8040101@shopzeus.com> <1459782597.3444051.568344234.048046C6@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de iPLQD1lAcGKeOeH6APJ/owOnEB1vGNYcLnwiuZ1LUM/g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; '"""': 0.05; 'that?': 0.05; 'url:bitbucket': 0.05; 'smallest': 0.07; 'subject:ANN': 0.07; 'tests,': 0.07; 'versions.': 0.07; 'welcome.': 0.07; 'closed.': 0.09; 'flags,': 0.09; 'immutable': 0.09; 'mutable': 0.09; 'received:internal': 0.09; 'def': 0.13; 'appropriate': 0.14; 'argument': 0.15; '::=': 0.16; 'bitbucket.': 0.16; 'boolean': 0.16; 'cleaner': 0.16; 'dependent.': 0.16; 'element2,': 0.16; 'increment': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'set-like': 0.16; 'singleton': 0.16; 'subject:Was': 0.16; 'subject:type': 0.16; 'time"': 0.16; 'wrote:': 0.16; 'element': 0.18; 'implementing': 0.18; 'all,': 0.20; '(the': 0.22; 'membership.': 0.22; '(or': 0.23; 'implemented': 0.24; 'header:In- Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; 'not.': 0.27; 'right.': 0.27; 'separate': 0.27; 'skip:( 20': 0.28; 'resolution': 0.28; 'consisting': 0.29; 'comments': 0.30; 'operations': 0.31; 'anyone': 0.32; 'another': 0.32; 'included': 0.32; 'skip:_ 10': 0.32; 'maybe': 0.33; 'useful': 0.33; 'url:python': 0.33; 'flags': 0.33; 'open': 0.33; 'could': 0.35; 'set.': 0.35; 'unit': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'possible': 0.36; '(i.e.': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'being': 0.37; 'sources': 0.37; 'suggestion': 0.37; 'starting': 0.37; 'doing': 0.38; 'received:66': 0.38; 'version': 0.38; 'test': 0.39; 'whatever': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'header:Message-Id:1': 0.61; 'skip:n 10': 0.62; 'making': 0.62; 'ending': 0.63; 'more': 0.63; 'url:0': 0.63; 'below.': 0.66; 'hour': 0.69; 'interested,': 0.69; '01:00': 0.84; 'discrete': 0.84; 'isolated': 0.84; "it'd": 0.84; 'nagy': 0.84; 'not)': 0.84; 'relation.': 0.84; 'testers': 0.84; 'difficult,': 0.91; 'subject:Set': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=lXOKWlt7h8nWgfjfSRFDn9yg4Lc=; b=aq0K92 mdeO5ClPZsXgbFvIaZ9FebzvrFTNQwwcJarCF0Zb9dpoQ/vwbdhOpoqPOH2LtBj/ ZRk8IDPlbEVX49lSxBtUTO4Bg33IxPwrpZ86cduxK57Pb/zyRaLjvkejxTcXyteV 0O3XdeSGLgOcS4FlcvJYzH9DSVZ0TFnVURNqk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=lXOKWlt7h8nWgfj fSRFDn9yg4Lc=; b=rShiPRwfP3JLQhdpXTvODeOGqK/I0AFRV9e1YG6sUuzFg9/ zdXWNWMtmu94/D6xEyImfegiu/GBjQrB15zLNqg8vhhxukvOm2g9g/LhriDSyos/ ACTHqocve62kIry6HlT6rQGKkir2KnHXPOkDe4gh3I83aBajzy5KsoEGuppQ= X-Sasl-Enc: re1AA5zi0yoqg09y2JeWWQ+NxD0nc3gmr7qpjxOG6UAI 1459782597 X-Mailer: MessagingEngine.com Webmail Interface - ajax-2373d6a1 In-Reply-To: <570213CB.8040101@shopzeus.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1459782597.3444051.568344234.048046C6@webmail.messagingengine.com> X-Mailman-Original-References: <56FE0625.5030901@shopzeus.com> <1459523394.2611014.565840994.593DD99A@webmail.messagingengine.com> <570213CB.8040101@shopzeus.com> Xref: csiph.com comp.lang.python:106445 On Mon, Apr 4, 2016, at 03:12, Nagy L=C3=A1szl=C3=B3 Zsolt wrote: >=20 > Hi All, >=20 > If anyone is interested, a module was born: >=20 > 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. >=20 > Also see below. >=20 > Yes, you are right. It is a set of non-intersecting intervals. >=20 > > 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 ::=3D (start_point_in_time, end_point_in_time) > >> intervalset ::=3D { 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 <=3D 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 argumen= t 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.