Skip to content

ENH: Intersection, Union and Difference methods for Interval and IntervalArray #58832

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

Closed
wants to merge 3 commits into from

Conversation

St0rmie
Copy link
Contributor

@St0rmie St0rmie commented May 26, 2024

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.

@St0rmie St0rmie requested a review from WillAyd as a code owner May 26, 2024 21:19
@St0rmie St0rmie force-pushed the feat-interval-operations branch from f80dccb to 1ce0720 Compare May 26, 2024 22:15
@jbrockmendel
Copy link
Member

Risk of confusion with intervalindex set methods?

@St0rmie
Copy link
Contributor Author

St0rmie commented May 26, 2024

Possibly. But as far as i can see the only one which might generate confusion is the intersection method. Should we give it another name?

@St0rmie St0rmie force-pushed the feat-interval-operations branch from 1ce0720 to a4573bb Compare May 26, 2024 23:23
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Jun 26, 2024
@St0rmie St0rmie force-pushed the feat-interval-operations branch from a4573bb to b9d81dc Compare June 26, 2024 01:01
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Jul 31, 2024
@mroeschke
Copy link
Member

Thanks for the PR, but it appears the core team isn't fully enthusiastic to support this feature at the moment, so closing. Happy to reopen if there's renewed interest.

@mroeschke mroeschke closed this Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Interval type should support intersection, union & overlaps & difference
4 participants