Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntervalSet.union and IntervalSet.intersection should accept Interval objects #25

Open
AlexandreDecan opened this issue Apr 1, 2018 · 2 comments

Comments

@AlexandreDecan
Copy link
Contributor

AlexandreDecan commented Apr 1, 2018

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)
@intiocean
Copy link
Owner

intiocean commented Apr 3, 2018

Nice - I hadn't considered that use case - I'd be happy to merge a change with your first suggestion and a couple of tests @AlexandreDecan :)

@AlexandreDecan
Copy link
Contributor Author

I'm sorry I didn't submit a PR for that. As I wanted interval arithmetic for Python asap, and as pyinter does not seem to be really maintained anymore, I created my own library (see https://github.com/AlexandreDecan/python-intervals).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants