Skip to content

Commit 700a9ed

Browse files
committed
dev
2 parents 28d9077 + a06275a commit 700a9ed

File tree

7 files changed

+94
-64
lines changed

7 files changed

+94
-64
lines changed

Changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ Version NEXTVERSION
55

66
* Read Zarr datasets with `cf.read`
77
(https://github.com/NCAS-CMS/cf-python/issues/863)
8+
* New keyword parameter to `cf.DimensionCoordinate.create_bounds`:
9+
``inplace`` (https://github.com/NCAS-CMS/cf-python/issues/855)
10+
* Set new minimum version of `dask`: ``2025.5.1``
11+
(https://github.com/NCAS-CMS/cf-python/issues/866)
812
* Changed dependency: ``cfdm>=1.12.2.0, <1.12.3.0``
13+
* Changed dependency: ``dask>=2025.5.1``
914

1015
----
1116

cf/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,17 @@
196196
f"Got {psutil.__version__} at {psutil.__file__}"
197197
)
198198

199+
# Check the version of dask
199200
try:
200201
import dask
201202
except ImportError as error1:
202203
raise ImportError(_error0 + str(error1))
203204
else:
204-
_minimum_vn = "2025.2.0"
205-
# Note in this case max is inclusive, change inequalities if this changes
206-
_maximum_vn = "2025.3.0"
207-
_dask_version = Version(dask.__version__)
208-
if _dask_version < Version(_minimum_vn) or _dask_version > Version(
209-
_maximum_vn
210-
):
211-
raise RuntimeError(
212-
"Bad dask version: cf requires "
213-
f"{_minimum_vn}<=dask<={_maximum_vn}. Got {_dask_version}."
205+
_minimum_vn = "2025.5.1"
206+
if Version(dask.__version__) < Version(_minimum_vn):
207+
raise ValueError(
208+
f"Bad dask version: cf requires dask>={_minimum_vn}. "
209+
f"Got {dask.__version__} at {dask.__file__}"
214210
)
215211

216212
try:

cf/dimensioncoordinate.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -533,18 +533,25 @@ def create_regular(cls, args, units=None, standard_name=None, bounds=True):
533533
return coordinate
534534

535535
def create_bounds(
536-
self, bound=None, cellsize=None, flt=0.5, max=None, min=None
536+
self,
537+
bound=None,
538+
cellsize=None,
539+
flt=0.5,
540+
max=None,
541+
min=None,
542+
inplace=False,
537543
):
538544
"""Create cell bounds.
539545
540-
Creates new cell bounds, irrespective of whether the cells
541-
already have cell bounds. The new bounds are not set on the
542-
dimension coordinate construct, but if that is desired they
543-
may always be added with the `set_bounds` method, for
544-
instance:
546+
When the operation is *not* in-place (the default), new bounds
547+
will be created and returned, regardless of whether or not
548+
bounds already exist, but the bounds are not set on the
549+
dimension coordinate construct.
545550
546-
>>> b = d.create_bounds()
547-
>>> d.set_bounds(b)
551+
If the operation is in-place (i.e. the *inplace* parameter is
552+
True) then the newly created bounds will be set on the
553+
dimension coordinate construct and `None` is returned, but
554+
only if there are no existing bounds.
548555
549556
By default, Voronoi cells are created by defining cell bounds
550557
that are half way between adjacent coordinate values. For
@@ -640,10 +647,13 @@ def create_bounds(
640647
``-90``: ``min=-90``, or ``min=cf.Data(-90,
641648
'degrees_north')``.
642649
650+
{{inplace: `bool`, optional}}
651+
643652
:Returns:
644653
645-
`Bounds`
646-
The new coordinate cell bounds.
654+
`Bounds` or `None`
655+
The new coordinate cell bounds, or `None` if the
656+
operation was in-place.
647657
648658
**Examples**
649659
@@ -756,6 +766,13 @@ def create_bounds(
756766
cftime.DatetimeGregorian(1985, 12, 1, 0, 0, 0, 0)]]
757767
758768
"""
769+
if inplace and self.has_bounds():
770+
raise ValueError(
771+
"Can't create dimension coordinate bounds in-place when "
772+
"bounds already exist. Existing bounds may be removed "
773+
"with the 'del_bounds' method."
774+
)
775+
759776
array = self.array
760777
size = array.size
761778

@@ -907,6 +924,10 @@ def create_bounds(
907924
# Create coordinate bounds object
908925
bounds = Bounds(data=Data(bounds, units=self.Units), copy=False)
909926

927+
if inplace:
928+
self.set_bounds(bounds)
929+
return
930+
910931
return bounds
911932

912933
def del_cell_characteristics(self, default=ValueError()):

cf/functions.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,50 +3187,50 @@ def environment(display=True, paths=True):
31873187
**Examples**
31883188
31893189
>>> cf.environment()
3190-
Platform: Linux-5.15.0-122-generic-x86_64-with-glibc2.35
3191-
HDF5 library: 1.12.2
3192-
netcdf library: 4.9.3-development
3193-
udunits2 library: /home/user/lib/libudunits2.so.0
3194-
esmpy/ESMF: 8.6.1 /home/user/lib/python3.12/site-packages/esmpy/__init__.py
3195-
Python: 3.12.2 /home/user/bin/python
3196-
dask: 2025.2.0 /home/user/lib/python3.12/site-packages/dask/__init__.py
3197-
netCDF4: 1.6.5 /home/user/lib/python3.12/site-packages/netCDF4/__init__.py
3198-
h5netcdf: 1.3.0 /home/user/lib/python3.12/site-packages/h5netcdf/__init__.py
3199-
h5py: 3.11.0 /home/user/lib/python3.12/site-packages/h5py/__init__.py
3200-
s3fs: 2024.6.0 /home/user/lib/python3.12/site-packages/s3fs/__init__.py
3201-
psutil: 5.9.8 /home/user/lib/python3.12/site-packages/psutil/__init__.py
3202-
packaging: 23.2 /home/user/lib/python3.12/site-packages/packaging/__init__.py
3203-
numpy: 1.26.4 /home/user/lib/python3.12/site-packages/numpy/__init__.py
3204-
scipy: 1.13.0 /home/user/lib/python3.12/site-packages/scipy/__init__.py
3205-
matplotlib: 3.8.4 /home/user/lib/python3.12/site-packages/matplotlib/__init__.py
3206-
cftime: 1.6.3 /home/user/lib/python3.12/site-packages/cftime/__init__.py
3207-
cfunits: 3.3.7 /home/user/lib/python3.12/site-packages/cfunits/__init__.py
3208-
cfplot: 3.3.0 /home/user/lib/python3.12/site-packages/cfplot/__init__.py
3209-
cfdm: 1.12.0.0 /home/user/cfdm/cfdm/__init__.py
3210-
cf: 3.17.0 /home/user/cf-python/cf/__init__.py
3190+
Platform: Linux-6.8.0-60-generic-x86_64-with-glibc2.39
3191+
HDF5 library: 1.14.2
3192+
netcdf library: 4.9.4-development
3193+
udunits2 library: libudunits2.so.0
3194+
esmpy/ESMF: 8.7.0 /home/miniconda/lib/python3.12/site-packages/esmpy/__init__.py
3195+
Python: 3.12.8 /home/miniconda/bin/python
3196+
dask: 2025.5.1 /home/miniconda/lib/python3.12/site-packages/dask/__init__.py
3197+
netCDF4: 1.7.2 /home/miniconda/lib/python3.12/site-packages/netCDF4/__init__.py
3198+
h5netcdf: 1.3.0 /home/miniconda/lib/python3.12/site-packages/h5netcdf/__init__.py
3199+
h5py: 3.12.1 /home/miniconda/lib/python3.12/site-packages/h5py/__init__.py
3200+
s3fs: 2024.12.0 /home/miniconda/lib/python3.12/site-packages/s3fs/__init__.py
3201+
psutil: 6.1.1 /home/miniconda/lib/python3.12/site-packages/psutil/__init__.py
3202+
packaging: 24.2 /home/miniconda/lib/python3.12/site-packages/packaging/__init__.py
3203+
numpy: 2.2.2 /home/miniconda/lib/python3.12/site-packages/numpy/__init__.py
3204+
scipy: 1.15.2 /home/miniconda/lib/python3.12/site-packages/scipy/__init__.py
3205+
matplotlib: 3.10.0 /home/miniconda/lib/python3.12/site-packages/matplotlib/__init__.py
3206+
cftime: 1.6.4.post1 /home/miniconda/lib/python3.12/site-packages/cftime/__init__.py
3207+
cfunits: 3.3.7 /home/miniconda/lib/python3.12/site-packages/cfunits/__init__.py
3208+
cfplot: 3.3.0 /home/miniconda/lib/python3.12/site-packages/cfplot/__init__.py
3209+
cfdm: 1.12.2.0 /home/miniconda/lib/python3.12/site-packages/cfdm/__init__.py
3210+
cf: NEXTVERSION /home/miniconda/lib/python3.12/site-packages/cf/__init__.py
32113211
32123212
>>> cf.environment(paths=False)
3213-
Platform: Linux-5.15.0-122-generic-x86_64-with-glibc2.35
3214-
HDF5 library: 1.12.2
3215-
netcdf library: 4.9.3-development
3216-
udunits2 library: /home/user/lib/libudunits2.so.0
3217-
esmpy/ESMF: 8.6.1
3218-
Python: 3.12.2
3219-
dask: 2025.2.0
3220-
netCDF4: 1.6.5
3213+
Platform: Linux-6.8.0-60-generic-x86_64-with-glibc2.39
3214+
HDF5 library: 1.14.2
3215+
netcdf library: 4.9.4-development
3216+
udunits2 library: libudunits2.so.0
3217+
esmpy/ESMF: 8.7.0
3218+
Python: 3.12.8
3219+
dask: 2025.5.1
3220+
netCDF4: 1.7.2
32213221
h5netcdf: 1.3.0
3222-
h5py: 3.11.0
3223-
s3fs: 2024.6.0
3224-
psutil: 5.9.8
3225-
packaging: 23.2
3226-
numpy: 1.26.4
3227-
scipy: 1.13.0
3228-
matplotlib: 3.8.4
3229-
cftime: 1.6.3
3222+
h5py: 3.12.1
3223+
s3fs: 2024.12.0
3224+
psutil: 6.1.1
3225+
packaging: 24.2
3226+
numpy: 2.2.2
3227+
scipy: 1.15.2
3228+
matplotlib: 3.10.0
3229+
cftime: 1.6.4.post1
32303230
cfunits: 3.3.7
32313231
cfplot: 3.3.0
3232-
cfdm: 1.12.0.0
3233-
cf: 3.17.0
3232+
cfdm: 1.12.2.0
3233+
cf: NEXTVERSION
32343234
32353235
"""
32363236
dependency_version_paths_mapping = {

cf/test/test_DimensionCoordinate.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,15 @@ def test_DimensionCoordinate_create_bounds(self):
544544
).all()
545545
)
546546

547+
# In-place
548+
self.assertFalse(d.has_bounds())
549+
self.assertIsNone(d.create_bounds(inplace=True))
550+
self.assertTrue(d.has_bounds())
551+
552+
# Fail when inplace=True and bounds already exist
553+
with self.assertRaises(ValueError):
554+
d.create_bounds(inplace=True)
555+
547556
# Cellsize units must be equivalent to the coordinate units,
548557
# or if the cell has no units then they are assumed to be
549558
# the same as the coordinates:

docs/source/installation.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ Required
194194

195195
* `numpy <http://www.numpy.org>`_, versions 2.0.0 or newer.
196196

197-
* `dask <https://pypi.org/project/dask>`_, version 2025.2.0 or newer up to
198-
2025.3.0 inclusive.
197+
* `dask <https://pypi.org/project/dask>`_, version 2025.5.1.
199198

200199
* `netCDF4 <https://pypi.org/project/netcdf4/>`_, 1.7.2 or newer.
201200

@@ -204,8 +203,8 @@ Required
204203

205204
* `scipy <https://pypi.org/project/scipy>`_, version 1.10.0 or newer.
206205

207-
* `cfdm <https://pypi.org/project/cfdm/>`_, version 1.12.1.0 or up to,
208-
but not including, 1.12.2.0.
206+
* `cfdm <https://pypi.org/project/cfdm/>`_, version 1.12.2.0 or up to,
207+
but not including, 1.12.3.0.
209208

210209
* `cfunits <https://pypi.org/project/cfunits/>`_, version 3.3.7 or newer.
211210

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ numpy>=2.0.0
44
cfdm>=1.12.1.0, <1.12.2.0
55
psutil>=0.6.0
66
cfunits>=3.3.7
7-
dask>=2025.2.0,<=2025.3.0
7+
dask>=2025.5.1
88
packaging>=20.0
99
scipy>=1.10.0

0 commit comments

Comments
 (0)