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

Support (half)-open intervals for wi query endpoints #740

Closed
sadielbartholomew opened this issue Mar 14, 2024 · 1 comment · Fixed by #753
Closed

Support (half)-open intervals for wi query endpoints #740

sadielbartholomew opened this issue Mar 14, 2024 · 1 comment · Fixed by #753
Assignees
Labels
enhancement New feature or request

Comments

@sadielbartholomew
Copy link
Member

sadielbartholomew commented Mar 14, 2024

It would be useful (as identified today for work towards the VISION project, context summary below) to be able to query on, not just a closed interval for a 'within a range' (wi) query, i.e. inclusive of the given endpoints, as is the only option at present, but an open (exclusive of the endpoints) and a half-open (inclusive on one side, for either side) condition.

To demonstrate, the behaviour of wi is:

>>> q = cf.wi(10, 20)
>>> q.evaluate(15)
True
>>> q.evaluate(10)
True
>>> q.evaluate(20)
True

but depending on context someone might want the evaluation results here to be (T, F, F), (T, T, F), or (T, F, T) instead. And equivalently for a without (wo) query.

This could be achieved with a compound query but it would be nicer to provide an interface to do this in one single query.

FYI the use case we had for our VISION project work, this would be especially handy for cases where querying is being done piecewise across a contiguous sequence, because with a closed interval there is double counting of the endpoints inside it.

Implementation proposal

As discussed today, the simplest and tentatively agreed way to implement this is via a pair of new keywords which enable the start and end of the interval, the lower and upper bound, to become open instead of closed. This would look to the user like so, where I am proposing the names open_lower and open_upper (but perhaps open0 and open1 could work also to match the value0 and value1 argument names) for those kwargs:

>>> q = cf.wi(10, 20)
>>> q.evaluate(15)
True
>>> q.evaluate(10)
True
>>> q.evaluate(10, open_lower=True)
False
>>> q.evaluate(20)
True
>>> q.evaluate(20, open_upper=True)
False

These kwargs would also be added to wo for the equivalent (half-)open queries. (see below)

Update: we've decided not to apply these to "wo" queries as well as "wi" queries, because in that context it would be quite confusing due to the inversion of the statement relative to "wi" - see #753 (comment).

@sadielbartholomew sadielbartholomew added the enhancement New feature or request label Mar 14, 2024
@sadielbartholomew sadielbartholomew self-assigned this Mar 14, 2024
@davidhassell
Copy link
Collaborator

Excellent.

@sadielbartholomew sadielbartholomew changed the title Support (half)-open intervals for wi and wo query endpoints Support (half)-open intervals for wi query endpoints Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants