From f46aeeb0ddecd4d6a7517c4c4e503276e0f8a828 Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Mon, 15 Jun 2026 11:43:59 +0100 Subject: [PATCH] to_restart: fix _FillValue incompatibility This fixes BOUT++ crashing on running restarts. Unlike the boutdata tool, the xBOUT restart tool let Xarray set the _FillValue attribute to NaN by default. When BOUT++ reads restart files, it rewrites all the attributes including this one, but Xarray doesn't allow _FillValue to be redefined, leading to a crash at launch. --- xbout/boutdataset.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xbout/boutdataset.py b/xbout/boutdataset.py index c316884c..10983c75 100644 --- a/xbout/boutdataset.py +++ b/xbout/boutdataset.py @@ -999,12 +999,24 @@ def to_restart( self.data, variables, savepath, nxpe, nype, tind, prefix, overwrite ) + # Xarray sets _FillValue=NaN by default for floating-point variables, + # but BOUT++ rewrites restart-file attributes after writing data, which + # NetCDF does not allow for _FillValue. Disable that default here. + restart_encoding = {} + if restart_datasets: + restart_encoding = { + name: {"_FillValue": None} + for name, variable in restart_datasets[0].variables.items() + if np.issubdtype(variable.dtype, np.floating) + } + with ProgressBar(): xr.save_mfdataset( restart_datasets, paths, compute=True, engine=_check_filetype(paths[0]), + encoding=restart_encoding, ) def animate_list(