Skip to content

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

@sadielbartholomew

Description

@sadielbartholomew

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).

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions