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

Overlaps() commutativity and atomic intervals #13

Closed
msarrel opened this issue Sep 12, 2019 · 13 comments
Closed

Overlaps() commutativity and atomic intervals #13

msarrel opened this issue Sep 12, 2019 · 13 comments
Labels
bug Something isn't working

Comments

@msarrel
Copy link

msarrel commented Sep 12, 2019

The overlaps() function seems to have some problem with commutativity and atomic intervals.

This example has a problem:

I.closed(1,1).overlaps(I.openclosed(1,2))
False (correct)
I.openclosed(1,2).overlaps(I.closed(1,1))
True (should be False)

But, this example succeeds:

I.closed(0,1).overlaps(I.openclosed(1,2))
False (correct)
I.openclosed(1,2).overlaps(I.closed(0,1))
False (correct)

There is a similar problem with union.

This example has a problem:

I.closed(1,1) | I.openclosed(1,2)
(1,2] (should be [1,2])
I.openclosed(1,2) | I.closed(1,1)
(1,2] (should be [1,2])

But, this example succeeds:

I.closed(0,1) | I.openclosed(1,2)
[0,2] (correct)
I.openclosed(1,2) | I.closed(0,1)
[0,2] (correct)

@AlexandreDecan
Copy link
Owner

Thanks for reporting those bugs! I'll have a look in a few minutes. The second bug (about unions) seems similar to the one I went into yesterday (see #12).

@AlexandreDecan AlexandreDecan added the bug Something isn't working label Sep 12, 2019
AlexandreDecan added a commit that referenced this issue Sep 12, 2019
@AlexandreDecan
Copy link
Owner

Bug should be fixed in the master branch, but I need to do more tests before releasing a change.
Meanwhile, you can use the master branch with pip install git+https://github.com/alexandredecan/python-intervals.

@msarrel
Copy link
Author

msarrel commented Sep 12, 2019

Thanks. I installed with pip from git as you suggest, and it seems to work. I look forward to the official release!

@AlexandreDecan
Copy link
Owner

I hope to release 1.9.0 within the next few days, but I still have to do more tests with a completely new feature (an dict-like data structure that allows to store and query data along with intervals).

I'll update this thread as soon as 1.9.0 will be available on PyPI ;)

@AlexandreDecan
Copy link
Owner

Release 1.9.0 is now available on PyPI.

@msarrel
Copy link
Author

msarrel commented Sep 17, 2019

Thank you so much. The IntervalDict looks very useful. It will replace some ad hoc code I had previously written. One feature that would be useful for me is to define addition, subtraction, etc. for IntervalDict. That is if we have two IntervalDicts:

[1, 3] | [5, 7] = 1
and
[2, 4] | [6, 8] = 2

Their sum would be a single Interval Dict with three entries:

[1, 2) | [5, 6) = 1
[2, 3) | [6, 7) = 3
[3, 4] | [7, 8] = 2

Regards,

Marc

@AlexandreDecan
Copy link
Owner

Thanks for your feedback! I'll think about this. I cannot add support for "+", "-", "*", etc. because it is tightly coupled with numbers, and this library does not make any assumption on what are used as bounds in intervals. However, I can imagine a rather generic d.combine(other_d, func=lambda x,y: x + y) that will do the trick.

@msarrel
Copy link
Author

msarrel commented Sep 17, 2019

The d.combine() approach would be sufficient for me. Thanks. Just to be clear, though, the func supplied in d.combine() would only apply to the values in the IntervalDict (the range), not the keys (the domain)?

@AlexandreDecan
Copy link
Owner

Yes, on the values, not on the keys. I'll open a new issue for this feature, so I won't forget about it :-D (I don't think I'll have time to work on this in the next few days)

@AlexandreDecan
Copy link
Owner

Just to be sure, when you wrote "apply to the values (the range) not the keys (the domain)", you mean the converse? (keys are intervals/ranges, values are what are stored along with intervals), right?

@AlexandreDecan
Copy link
Owner

FYI, IntervalDict.combine is now available from the master branch. It will be part of the next release (probably 1.10.0). I don't know when this release will be available, it will depends on the number of other changes I would like to put in.

@AlexandreDecan
Copy link
Owner

Release 1.10.0 is now available on PyPI.

@msarrel
Copy link
Author

msarrel commented Sep 26, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants