cf.wi

cf.wi(value0, value1, units=None, attr=None, open_lower=False, open_upper=False)[source]

A Query object for a “within a range” condition.

The condition is a closed interval by default, inclusive of both the endpoints, but can be made open or half-open to exclude the endpoints on either end with use of the open_lower and open_upper parameters.

Parameters
value0:

The lower bound of the range.

value1:

The upper bound of the range.

open_lower: bool, optional

If True, open the interval at the lower bound so that value0 is excluded from the range. By default the interval is closed so that value0 is included.

New in version 3.16.2.

open_upper: bool, optional

If True, open the interval at the upper bound so that value1 is excluded from the range. By default the interval is closed so that value1 is included.

New in version 3.16.2.

units: str or Units, optional

The units of value. By default, the same units as the operand being tested are assumed, if applicable. If units is specified and value already has units (such as those attached to a Data object), then the pair of units must be equivalent.

attr: str, optional

Apply the condition to the attribute, or nested attributes, of the operand, rather than the operand itself. Nested attributes are specified by separating them with a .. For example, the “month” attribute of the “bounds” attribute is specified as 'bounds.month'.

Returns
Query

The query object.

Examples

>>> q = cf.wi(5, 7)
>>> q
<CF Query: wi (5, 7)>
>>> q.evaluate(6)
True
>>> q.evaluate(4)
False
>>> q.evaluate(5)
True
>>> q.evaluate(7)
True

The interval can be made open on either side or both. Note that, as per mathematical interval notation, square brackets indicate closed endpoints and parentheses open endpoints in the representation:

>>> q = cf.wi(5, 7, open_upper=True)
>>> q
<CF Query: (wi [5, 7))>
>>> q.evaluate(7)
False
>>> q = cf.wi(5, 7, open_lower=True)
>>> q
<CF Query: (wi (5, 7])>
>>> q.evaluate(5)
False
>>> q = cf.wi(5, 7, open_lower=True, open_upper=True)
>>> q
<CF Query: (wi (5, 7))>
>>> q.evaluate(5)
False
>>> q.evaluate(7)
False