cf.persist_data

cf.persist_data(*arg)[source]

Control the persistence of computed data.

If True then a computed cf.Data instance will cache the entire computed array (in chunks) in memory, ready for fast future access. If False then computed data is not cached.

This behaviour may be overridden on an individual basis by the persist parameter of the cf.Data.compute method.

Added in version (cfdm): 1.13.1.0

Parameters:
arg: bool or Constant, optional

The new data display option. The default is to not change the current value.

Returns:
Constant

The value prior to the change, or the current value if no new value was specified.

Examples

>>> cf.persist_data()
<CF Constant: False>
>>> print(cf.persist_data())
False
>>> bool(cf.persist_data())
False
>>> cf.persist_data().value
False
>>> old = cf.persist_data(True)
>>> cf.persist_data()
<CF Constant: True>
>>> cf.persist_data(old)
<CF Constant: False>
>>> cf.persist_data()
<CF Constant: False>

Use as a context manager:

>>> print(cf.persist_data())
False
>>> with cf.persist_data(True):
...     print(cf.persist_data())
...
True
>>> print(cf.persist_data())
False