Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Version NEXTVERSION
--------------
----------------

**2025-??-??**

* New keyword parameter to `cfdm.Field.dump`: ``data``
(https://github.com/NCAS-CMS/cfdm/issues/345)
* New dependency: ``distributed>=2025.5.1``

----
Expand Down
39 changes: 35 additions & 4 deletions cfdm/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ def creation_commands(
return out

@_display_or_return
def dump(self, display=True, _level=0, _title=None):
def dump(self, data=True, display=True, _level=0, _title=None):
"""A full description of the field construct.

Returns a description of all properties, including those of
Expand All @@ -1798,6 +1798,22 @@ def dump(self, display=True, _level=0, _title=None):

:Parameters:

data: `bool`, optional
If True (the default) then display the first and last
Field data values. This can take a long time if the
data needs an expensive computation (possibly
including a slow read from local or remote disk), in
which case setting *data* to False will not display
these values, thereby avoiding the computational
cost. This only applies to the Field's data - the
first and last values of data arrays stored in
metadata constructs are always displayed.

Note that when the first and last values are
displayed, they are cached for fast future retrieval.

.. versionadded:: NEXTVERSION

display: `bool`, optional
If False then return the description as a string. By
default the description is printed.
Expand Down Expand Up @@ -1839,12 +1855,27 @@ def dump(self, display=True, _level=0, _title=None):
string.append(self._dump_properties(_level=_level))

# Data
data = self.get_data(None)
if data is not None:
d = self.get_data(None)
if d is not None:
x = [axis_to_name[axis] for axis in self.get_data_axes(default=())]
x = f"{indent0}Data({', '.join(x)})"
if data:
# Show selected data values
x += f" = {d}"
else:
# Don't show any data values
units = d.Units
if units.isreftime:
calendar = getattr(units, "calendar", None)
if calendar is not None:
x += f" {calendar}"
else:
units = getattr(units, "units", None)
if units is not None:
x += f" {units}"

string.append("")
string.append(f"{indent0}Data({', '.join(x)}) = {data}")
string.append(x)
string.append("")

# Quantization
Expand Down
1 change: 1 addition & 0 deletions cfdm/test/test_Field.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_Field__repr__str__dump_construct_type(self):
repr(f)
str(f)
self.assertIsInstance(f.dump(display=False), str)
self.assertIsInstance(f.dump(data=False, display=False), str)
self.assertEqual(f.construct_type, "field")

# Test when any construct which can have data in fact has no data.
Expand Down