Skip to content

Commit

Permalink
Merge pull request #671 from davidhassell/cache-compressed
Browse files Browse the repository at this point in the history
In `cf.read`, skip caching elements from compression index variables.
  • Loading branch information
davidhassell committed Jun 20, 2023
2 parents 6c55e06 + 968f5a2 commit 9f676f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
)

# Check the version of cfdm
_minimum_vn = "1.10.1.0"
_minimum_vn = "1.10.1.1"
_maximum_vn = "1.10.2.0"
_cfdm_version = Version(cfdm.__version__)
if not Version(_minimum_vn) <= _cfdm_version < Version(_maximum_vn):
Expand Down
26 changes: 20 additions & 6 deletions cf/read_write/netcdf/netcdfread.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def _create_data(
parent_ncvar=None,
coord_ncvar=None,
cfa_term=None,
compression_index=False,
):
"""Create data for a netCDF or CFA-netCDF variable.
Expand Down Expand Up @@ -181,6 +182,12 @@ def _create_data(
.. versionadded:: 3.15.0
compression_index: `bool`, optional
True if the data being created are compression
indices.
.. versionadded:: 3.15.2
:Returns:
`Data`
Expand All @@ -201,12 +208,19 @@ def _create_data(
# one dask chunk
if data.npartitions == 1:
data._cfa_set_write(True)

if self.implementation.get_construct_type(construct) != "field":
# Only cache values from non-field data, on the
# assumption that field data is, in general, so large
# that finding the cached values takes too long. See
# method `_cache_data_elements` for details.
if (
not compression_index
and self.implementation.get_construct_type(construct)
!= "field"
):
# Only cache values from non-field data and
# non-compression-index data, on the assumptions that:
#
# a) Field data is, in general, so large that finding
# the cached values takes too long.
#
# b) Cached values are never really required for
# compression index data.
self._cache_data_elements(data, ncvar)

return data
Expand Down
2 changes: 1 addition & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Required
* `cftime <https://pypi.org/project/cftime/>`_, version 1.6.2 or newer
(note that this package may be installed with netCDF4).

* `cfdm <https://pypi.org/project/cfdm/>`_, version 1.10.1.0 or up to,
* `cfdm <https://pypi.org/project/cfdm/>`_, version 1.10.1.1 or up to,
but not including, 1.10.2.0.

* `cfunits <https://pypi.org/project/cfunits/>`_, version 3.3.6 or newer.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
netCDF4>=1.5.4
cftime>=1.6.2
numpy>=1.22
cfdm>=1.10.1.0, <1.10.2.0
cfdm>=1.10.1.1, <1.10.2.0
psutil>=0.6.0
cfunits>=3.3.6
dask>=2022.12.1
Expand Down

0 comments on commit 9f676f5

Please sign in to comment.