Skip to content

Commit 6eeb074

Browse files
authored
Merge pull request #914 from davidhassell/display-data
Control setting and display of cached data elements
2 parents 76c98f3 + d6b34a9 commit 6eeb074

7 files changed

Lines changed: 193 additions & 113 deletions

File tree

Changelog.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
Version NEXTVERSION
22
-------------------
33

4-
**2025-12-??**
5-
4+
**2026-01-??**
5+
6+
* New function to control the creation of cached elements during data
7+
display: `cf.display_data`
8+
(https://github.com/NCAS-CMS/cf-python/issues/913)
9+
* New methods: `cf.Data.get_cached_elements`,
10+
`cf.Data.cache_elements`
11+
(https://github.com/NCAS-CMS/cf-python/issues/913)
12+
* Set cached elements during `cf.Data.__init__`
13+
(https://github.com/NCAS-CMS/cf-python/issues/913)
14+
* Removed the `cf.constants.CONSTANTS` dictionary, replacing it
15+
with `cf.ConstantAccess.constants`
16+
(https://github.com/NCAS-CMS/cf-python/issues/902)
617
* Reduce the time taken to import `cf`
718
(https://github.com/NCAS-CMS/cf-python/issues/902)
19+
* Changed dependency: ``cfdm>=1.12.4.0, <1.12.5.0``
820

921
----
1022

cf/functions.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def configuration(
156156
tempdir=None,
157157
chunksize=None,
158158
log_level=None,
159+
display_data=None,
159160
regrid_logging=None,
160161
relaxed_identities=None,
161162
bounds_combination_mode=None,
@@ -177,6 +178,7 @@ def configuration(
177178
* `tempdir`
178179
* `chunksize`
179180
* `log_level`
181+
* `display_data`
180182
* `regrid_logging`
181183
* `relaxed_identities`
182184
* `bounds_combination_mode`
@@ -200,10 +202,10 @@ def configuration(
200202
.. versionadded:: 3.6.0
201203
202204
.. seealso:: `atol`, `rtol`, `tempdir`, `chunksize`,
203-
`total_memory`, `log_level`, `regrid_logging`,
204-
`relaxed_identities`, `bounds_combination_mode`,
205-
`active_storage`, `active_storage_url`,
206-
`active_storage_max_requests`
205+
`total_memory`, `log_level`, `display_data`,
206+
`regrid_logging`, `relaxed_identities`,
207+
`bounds_combination_mode`, `active_storage`,
208+
`active_storage_url`, `active_storage_max_requests`
207209
208210
:Parameters:
209211
@@ -245,6 +247,12 @@ def configuration(
245247
* ``'DETAIL'`` (``3``);
246248
* ``'DEBUG'`` (``-1``).
247249
250+
display_data `bool` or `Constant`, optional
251+
The new display data option. The default is to not change
252+
the current behaviour.
253+
254+
.. versionadded:: NEXTVERSION
255+
248256
regrid_logging: `bool` or `Constant`, optional
249257
The new value (either True to enable logging or False to
250258
disable it). The default is to not change the current
@@ -303,6 +311,7 @@ def configuration(
303311
'log_level': 'WARNING',
304312
'bounds_combination_mode': 'AND',
305313
'chunksize': 82873466.88000001,
314+
'display_data': True,
306315
'active_storage': False,
307316
'active_storage_url': None,
308317
'active_storage_max_requests': 100}
@@ -320,6 +329,7 @@ def configuration(
320329
'log_level': 'WARNING',
321330
'bounds_combination_mode': 'AND',
322331
'chunksize': 75000000.0,
332+
'display_data': True,
323333
'active_storage': False,
324334
'active_storage_url': None,
325335
'active_storage_max_requests': 100}
@@ -347,6 +357,7 @@ def configuration(
347357
'log_level': 'INFO',
348358
'bounds_combination_mode': 'AND',
349359
'chunksize': 75000000.0,
360+
'display_data': True,
350361
'active_storage': False,
351362
'active_storage_url': None}
352363
>>> with cf.configuration(atol=9, rtol=10):
@@ -360,6 +371,7 @@ def configuration(
360371
'log_level': 'INFO',
361372
'bounds_combination_mode': 'AND',
362373
'chunksize': 75000000.0,
374+
'display_data': True,
363375
'active_storage': False,
364376
'active_storage_url': None,
365377
'active_storage_max_requests': 100}
@@ -372,6 +384,7 @@ def configuration(
372384
'log_level': 'INFO',
373385
'bounds_combination_mode': 'AND',
374386
'chunksize': 75000000.0,
387+
'display_data': True,
375388
'active_storage': False,
376389
'active_storage_url': None,
377390
'active_storage_max_requests': 100}
@@ -402,6 +415,7 @@ def configuration(
402415
new_tempdir=tempdir,
403416
new_chunksize=chunksize,
404417
new_log_level=log_level,
418+
new_display_data=display_data,
405419
new_regrid_logging=regrid_logging,
406420
new_relaxed_identities=relaxed_identities,
407421
bounds_combination_mode=bounds_combination_mode,
@@ -445,6 +459,7 @@ def _configuration(_Configuration, **kwargs):
445459
"new_tempdir": tempdir,
446460
"new_chunksize": chunksize,
447461
"new_log_level": log_level,
462+
"new_display_data": display_data,
448463
"new_regrid_logging": regrid_logging,
449464
"new_relaxed_identities": relaxed_identities,
450465
"bounds_combination_mode": bounds_combination_mode,
@@ -459,10 +474,6 @@ def _configuration(_Configuration, **kwargs):
459474

460475
old = ConstantAccess.constants(copy=True)
461476

462-
# old = {name.lower(): val for name, val in CONSTANTS.items()}
463-
#
464-
# old.pop("total_memory", None)
465-
466477
# Filter out 'None' kwargs from configuration() defaults. Note that this
467478
# does not filter out '0' or 'True' values, which is important as the user
468479
# might be trying to set those, as opposed to None emerging as default.
@@ -552,7 +563,6 @@ def FREE_MEMORY():
552563
# Functions inherited from cfdm
553564
# --------------------------------------------------------------------
554565
class ConstantAccess(cfdm.ConstantAccess):
555-
_constants = {}
556566
_Constant = Constant
557567

558568
def __docstring_substitutions__(self):
@@ -576,6 +586,10 @@ class log_level(ConstantAccess, cfdm.log_level):
576586
_reset_log_emergence_level = _reset_log_emergence_level
577587

578588

589+
class display_data(ConstantAccess, cfdm.display_data):
590+
pass
591+
592+
579593
class regrid_logging(ConstantAccess):
580594
"""Whether or not to enable `esmpy` regridding logging.
581595

cf/mixin/properties.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
_DEPRECATION_ERROR_KWARGS,
88
_DEPRECATION_ERROR_METHOD,
99
)
10-
from ..functions import atol as cf_atol
11-
from ..functions import rtol as cf_rtol
1210
from ..mixin_container import Container
1311
from ..query import Query
1412
from ..units import Units
@@ -34,32 +32,6 @@ def __new__(cls, *args, **kwargs):
3432
instance._Data = Data
3533
return instance
3634

37-
# ----------------------------------------------------------------
38-
# Private attributes
39-
# ----------------------------------------------------------------
40-
@property
41-
def _atol(self):
42-
"""Return the tolerance on absolute differences between real
43-
numbers, as returned by the `cf.atol` function.
44-
45-
This is used by, for example, the `_equals` method.
46-
47-
"""
48-
return cf_atol().value
49-
50-
@property
51-
def _rtol(self):
52-
"""Return the tolerance on relative differences between real
53-
numbers, as returned by the `cf.rtol` function.
54-
55-
This is used by, for example, the `_equals` method.
56-
57-
"""
58-
return cf_rtol().value
59-
60-
# ----------------------------------------------------------------
61-
# Private methods
62-
# ----------------------------------------------------------------
6335
def _matching_values(self, value0, value1, units=False, basic=False):
6436
"""Whether two values match.
6537
@@ -100,9 +72,6 @@ def _matching_values(self, value0, value1, units=False, basic=False):
10072

10173
return self._equals(value1, value0, basic=basic)
10274

103-
# ----------------------------------------------------------------
104-
# Attributes
105-
# ----------------------------------------------------------------
10675
@property
10776
def id(self):
10877
"""An identity for the {{class}} object.
@@ -150,9 +119,6 @@ def id(self):
150119
f"{self.__class__.__name__} doesn't have attribute 'id'"
151120
)
152121

153-
# ----------------------------------------------------------------
154-
# CF properties
155-
# ----------------------------------------------------------------
156122
@property
157123
def calendar(self):
158124
"""The calendar CF property.
@@ -554,9 +520,6 @@ def valid_range(self, value):
554520
def valid_range(self):
555521
self.del_property("valid_range", default=AttributeError())
556522

557-
# ----------------------------------------------------------------
558-
# Methods
559-
# ----------------------------------------------------------------
560523
def get_property(self, prop, default=ValueError()):
561524
"""Get a CF property.
562525

cf/mixin2/container.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
from ..docstring import _docstring_substitution_definitions
9-
from ..functions import atol, rtol
109

1110

1211
class Container:
@@ -55,23 +54,3 @@ def __docstring_package_depth__(self):
5554
5655
"""
5756
return 0
58-
59-
@property
60-
def _atol(self):
61-
"""Internal alias for `{{package}}.atol`.
62-
63-
An alias is necessary to avoid a name clash with the keyword
64-
argument of identical name (`atol`) in calling functions.
65-
66-
"""
67-
return atol().value
68-
69-
@property
70-
def _rtol(self):
71-
"""Internal alias for `{{package}}.rtol`.
72-
73-
An alias is necessary to avoid a name clash with the keyword
74-
argument of identical name (`rtol`) in calling functions.
75-
76-
"""
77-
return rtol().value

cf/read_write/um/umread.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,7 +3575,7 @@ def read(
35753575
# Return now if there are valid file types
35763576
return []
35773577

3578-
f = self.file_open(filename, parse=True)
3578+
f = self.dataset_open(filename, parse=True)
35793579

35803580
info = is_log_level_info(logger)
35813581

@@ -3598,7 +3598,7 @@ def read(
35983598
for var in f.vars
35993599
]
36003600

3601-
self.file_close()
3601+
self.dataset_close()
36023602

36033603
return [field for x in um for field in x.fields if field]
36043604

@@ -3632,7 +3632,7 @@ def _open_um_file(
36323632
The open PP or FF file object.
36333633
36343634
"""
3635-
self.file_close()
3635+
self.dataset_close()
36363636
try:
36373637
f = File(
36383638
filename,
@@ -3678,15 +3678,15 @@ def is_um_file(self, filename):
36783678
try:
36793679
# Note: No need to completely parse the file to ascertain
36803680
# if it's PP or FF.
3681-
self.file_open(filename, parse=False)
3681+
self.dataset_open(filename, parse=False)
36823682
except Exception:
3683-
self.file_close()
3683+
self.dataset_close()
36843684
return False
36853685
else:
3686-
self.file_close()
3686+
self.dataset_close()
36873687
return True
36883688

3689-
def file_close(self):
3689+
def dataset_close(self):
36903690
"""Close the file that has been read.
36913691
36923692
:Returns:
@@ -3700,7 +3700,7 @@ def file_close(self):
37003700

37013701
self._um_file = None
37023702

3703-
def file_open(self, filename, parse=True):
3703+
def dataset_open(self, filename, parse=True):
37043704
"""Open the file for reading.
37053705
37063706
:Paramters:

0 commit comments

Comments
 (0)