-
Notifications
You must be signed in to change notification settings - Fork 106
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
Chop datafunc needs chop interval #112
Comments
The
Note that if the |
The interval data field in my application is a time series, and in my datafunc function, I want to cut out the part of the time series not belonging to chop interval. The problem is the datafunc function does not have access to the endpoints of the chop interval needed to do this. Although now that I think of it, there is a work-around to the problem. I have an "extended" datafunc function also takes in the chop interval endpoints, and then use a lambda function to pass in these endpoints and create the desired datafunc for the chop function. |
Found this when I had the same question for Problem def datafunc(sliced_interval, islower):
a, b, _ = sliced_interval
if islower:
return f"new data = remove ['point', {b}) from [{a}, {b})"
return f"new data = remove [{a}, 'point') from [{a}, {b})"
t = IntervalTree([Interval(0, 10), Interval(5, 15)])
t.slice(6, datafunc) Result where datafunc does not have access to slice point 6
[Interval(0, 6, "new data = remove ['point', 10) from [0, 10)"),
Interval(5, 6, "new data = remove ['point', 15) from [5, 15)"),
Interval(6, 10, "new data = remove [0, 'point') from [0, 10)"),
Interval(6, 15, "new data = remove [5, 'point') from [5, 15)")] Solution inspired by @chaimleib def slice_the_tree(t, point):
def datafunc(sliced_interval, islower):
a, b, _ = sliced_interval
if islower:
return f"new data = remove [{point}, {b}) from [{a}, {b})"
return f"new data = remove [{a}, {point}) from [{a}, {b})"
t.slice(point, datafunc)
t = IntervalTree([Interval(0, 10), Interval(5, 15)])
slice_the_tree(t, 6) Result where datafunc has access to slice point 6
[Interval(0, 6, 'new data = remove [6, 10) from [0, 10)'),
Interval(5, 6, 'new data = remove [6, 15) from [5, 15)'),
Interval(6, 10, 'new data = remove [0, 6) from [0, 10)'),
Interval(6, 15, 'new data = remove [5, 6) from [5, 15)')] Solution inspired by @jeffwu78 def extended_datafunc(sliced_interval, islower, point):
a, b, _ = sliced_interval
if islower:
return f"new data = remove [{point}, {b}) from [{a}, {b})"
return f"new data = remove [{a}, {point}) from [{a}, {b})"
t = IntervalTree([Interval(0, 10), Interval(5, 15)])
t.slice(6, lambda sliced_interval, islower: extended_datafunc(sliced_interval, islower, 6)) Result as above
[Interval(0, 6, 'new data = remove [6, 10) from [0, 10)'),
Interval(5, 6, 'new data = remove [6, 15) from [5, 15)'),
Interval(6, 10, 'new data = remove [0, 6) from [0, 10)'),
Interval(6, 15, 'new data = remove [5, 6) from [5, 15)')] More legible adaptation This solution uses the from functools import partial
t = IntervalTree([Interval(0, 10), Interval(5, 15)])
t.slice(6, partial(extended_datafunc, point=6)) |
The chop datafunc has access to the old interval and whether it is a lower or upper chop, but it does not have access to the requested chop interval. This seems like a major oversight. Am I missing something?
To clarify, in the example given the documentation
datafunc is given access to the old interval (0, 10), but not the actual chop interval (3, 7).
The text was updated successfully, but these errors were encountered: