-
Notifications
You must be signed in to change notification settings - Fork 23
Description
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)
Truebut 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)
FalseThese kwargs would also be added to (see below)wo for the equivalent (half-)open queries.