Giter VIP home page Giter VIP logo

pyinter's People

Contributors

alexandredecan avatar bouk avatar dimonb avatar dterror-zz avatar intiocean avatar kevincox avatar skatenerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyinter's Issues

Extrama <= and >= should equal themselves.

Each infinity has one comparison-and-equality operator that returns False if the values are equal. It would be nice if this could be fixed.

Tests that show the issue:

assert NEGATIVE_INFINITY >= NEGATIVE_INFINITY
assert INFINITY <= INFINITY

IntervalSet.union and IntervalSet.intersection should accept Interval objects

Right now, it's not possible to write closed(3,4) | closed(5,6) | closed(4,5). It results in a TypeError saying that Interval object is not iterable.

The current workaround is to wrap the Interval object into a IntervalSet, e.g. closed(3,4) | closed(5,6) | IntervalSet([closed(4,5)]) which is not very convenient.

A simple way to support the first notation could be to add:

other = IntervalSet([other]) if isinstance(other, Interval) else other

It could actually be a good idea to have Interval objects also supporting IntervalSet. In that case, an easy way could be to add:

if isinstance(other, IntervalSet):
  return other.union(self)

Difficult to debug strings in intervals

Currently it's very difficult to tell if a user accidentally passed in strings to pyinterval.closedopen. For instance, in the case of:

bad_interval =  pyinterval.closedopen('100','200')

The repr() and str() modules don't show the quotes around the values, so it looks like you passed in integers. The only way to tell is by using

bad_interval._data._lower_value
bad_interval._data._upper_value

I understand you want the module to be type-agnostic, which is admirable, but making repr() look like:

['100','200')

instead of:

[100,200)

might make it easier to debug problems.

Quadratic performance characteristics

pyinter is incredibly slow; adding a thousand intervals requires a million operations, because add() loops over all the existing elements in the set.

add() (and similar functions) should take advantage of the sorted order and only touch elements which intersect other.

use cases for integer intervals

I'm just beginning to use this in an application and it's integers I'm interested in.

So far I'm standardizing on a helper function lambda i: pyinter.closedopen(i,i+1)

Next I'm planning to implement an iterator of iterators, where each interval in an IntervalSet is mapped to a standard range object and the whole mess is iterated to enumerate, in order, the integers in the set.

Assuming this works reasonably well I'll hack it into the code and docs and add a pull request. If you have a better suggestion I'm all ears.

IntervalSet should take *args instead of needing an iterable to be passed in

It makes the use of it nicer. You can then do something like this:

IntervalSet(interval1, interval2, interval3, ...)

Instead of having to make a list out of your items before passing them in

IntervalSet([interval1, interval2, interval3])

The reason it was created in this way to start with was to match the Python inbuilt set initialisation but I don't think it needs to match.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.