ENH: Intersection, Union and Difference methods for Interval and IntervalArray #58832
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
doc/source/whatsnew/v3.0.0.rst
file if fixing a bug or adding a new feature.1) Description
Me and @Leventide have implemented the following methods for Interval and IntervalArray operations:
1.1) Interval methods
- Intersection
The 'Intersection' method returns the common points between two intervals in a form of Interval or None if there is no intersection.
- Union
The 'Union' method returns all the points present in atleast one of the intervals. It returns this result in a form of an numpy array of Intervals.
- Difference
The 'Difference' method returns the points in the first interval that aren't contained in the second interval. It returns this result in a form of an numpy array of Intervals.
1.2) IntervalArray methods
The corresponding methods for the IntervalArray apply the operation element by element. In other words, it calculates the result based on each interval in the array with the given interval.
- Intersection
The 'Intersection' method returns an numpy array of Intervals containing the Intersections between each interval and the given one.
- Union
The 'Union' method returns an array of arrays of Intervals containing the unions between each interval and the given one.
- Difference
The 'Difference' method returns an array of arrays of Intervals containing the differences between each interval and the given one.
2) Why didn't we use IntervalArray instead of numpy arrays:
IntervalArray can only contain Intervals that are equally closed. For operations such as union and difference between intervals, since the result can have two intervals that aren't equally closed, using IntervalArray wouldn't return the proper result.
3) Are there other implementations of these methods already available?
We saw that https://piso.readthedocs.io/en/latest/reference/interval.html has a implementation for these methods. However, since it uses IntervalArray it can only handle correctly operations between intervals that are equally closed. By using numpy arrays we can apply these methods correctly for any kind of interval.