diff --git a/cf/data/data.py b/cf/data/data.py index f9c2d3bb50..2ba56705d7 100644 --- a/cf/data/data.py +++ b/cf/data/data.py @@ -9105,25 +9105,16 @@ def dump(self, display=True, prefix=None): if prefix is None: prefix = self.__class__.__name__ - string = ["{0}.shape = {1}".format(prefix, self._shape)] + string = [f"{prefix}.shape = {self.shape}"] - if self._size == 1: - string.append( - "{0}.first_datum = {1}".format(prefix, self.datum(0)) - ) + if self.size == 1: + string.append(f"{prefix}.first_datum = {self.datum(0)}") else: - string.append( - "{0}.first_datum = {1}".format(prefix, self.datum(0)) - ) - string.append( - "{0}.last_datum = {1}".format(prefix, self.datum(-1)) - ) + string.append(f"{prefix}.first_datum = {self.datum(0)}") + string.append(f"{prefix}.last_datum = {self.datum(-1)}") for attr in ("fill_value", "Units"): - string.append( - "{0}.{1} = {2!r}".format(prefix, attr, getattr(self, attr)) - ) - # --- End: for + string.append(f"{prefix}.{attr} = {getattr(self, attr)!r}") return "\n".join(string) diff --git a/cf/functions.py b/cf/functions.py index ebb12c20fa..4c8355a38f 100644 --- a/cf/functions.py +++ b/cf/functions.py @@ -13,7 +13,6 @@ from collections.abc import Iterable from itertools import product from marshal import dumps -from math import ceil as math_ceil from numbers import Integral from os import getpid, listdir, mkdir from os.path import abspath as _os_path_abspath @@ -25,9 +24,9 @@ import cfdm import netCDF4 +import numpy as np from dask import config from dask.utils import parse_bytes -import numpy as np from numpy import __file__ as _numpy__file__ from numpy import __version__ as _numpy__version__ from numpy import all as _numpy_all diff --git a/cf/test/test_Data.py b/cf/test/test_Data.py index 9e6a610ab8..31e603279a 100644 --- a/cf/test/test_Data.py +++ b/cf/test/test_Data.py @@ -3938,6 +3938,14 @@ def test_Data_tolist(self): self.assertEqual(e, np.array(x).tolist()) self.assertTrue(d.equals(cf.Data(e))) + def test_Data_dump(self): + d = cf.Data([1, 2], "m") + x = ( + "Data.shape = (2,)\nData.first_datum = 1\nData.last_datum = 2\n" + "Data.fill_value = None\nData.Units = " + ) + self.assertEqual(d.dump(display=False), x) + if __name__ == "__main__": print("Run date:", datetime.datetime.now())