cf.Data.__contains__

Data.__contains__(value)[source]

Membership test operator in

x.__contains__(y) <==> y in x

Returns True if the scalar value is contained anywhere in the data. If value is not scalar then an exception is raised.

Performance

__contains__ causes all delayed operations to be computed unless value is a Data object with incompatible units, in which case False is always returned.

Examples

>>> d = cf.Data([[0, 1, 2], [3, 4, 5]], 'm')
>>> 4 in d
True
>>> 4.0 in d
True
>>> cf.Data(5) in d
True
>>> cf.Data(5, 'm') in d
True
>>> cf.Data(0.005, 'km') in d
True
>>> 99 in d
False
>>> cf.Data(2, 'seconds') in d
False
>>> [1] in d
Traceback (most recent call last):
    ...
TypeError: elementwise comparison failed; must test against a scalar, not [1]
>>> [1, 2] in d
Traceback (most recent call last):
    ...
TypeError: elementwise comparison failed; must test against a scalar, not [1, 2]
>>> d = cf.Data(["foo", "bar"])
>>> 'foo' in d
True
>>> 'xyz' in d
False