Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for print when no dimension coordinate data #175

Merged
merged 1 commit into from
Mar 1, 2022
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
11 changes: 11 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Version 1.9.?.?
---------------

**2022-0?-??**

* Fixed bug that caused `cf.Domain.__str__` to fail when a dimension
coordinate construct does not have data
(https://github.com/NCAS-CMS/cfdm/issues/174)

----

Version 1.9.0.2
---------------

Expand Down
7 changes: 5 additions & 2 deletions cfdm/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,18 @@ def _print_item(self, cid, variable, axes):

x = []
dimension_coordinates = self.dimension_coordinates(todict=True)
for axis_cid in sorted(self.domain_axes(todict=True)):
for axis_cid, axis in sorted(self.domain_axes(todict=True).items()):
for cid, dim in dimension_coordinates.items():
if construct_data_axes[cid] == (axis_cid,):
name = dim.identity(default=f"key%{0}")
y = f"{name}({dim.get_data().size})"
y = f"{name}({axis.get_size()})"
if y != axis_names[axis_cid]:
y = f"{name}({axis_names[axis_cid]})"

if dim.has_data():
y += f" = {dim.get_data()}"
else:
y += " = "

x.append(y)

Expand Down
7 changes: 7 additions & 0 deletions cfdm/test/test_Domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def test_Domain__repr__str__dump(self):
for title in (None, "title"):
d.dump(display=False, _title=title)

# Test when dimension coordinate has no data
d = d.copy()
t = d.construct("time")
t.del_data()
self.assertFalse(t.has_data())
str(d)

def test_Domain__init__(self):
"""Test the Domain constructor and source keyword."""
cfdm.Domain(source="qwerty")
Expand Down
8 changes: 4 additions & 4 deletions joss/paper.bib
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ @misc{Eaton:2020
title = {{{NetCDF Climate}} and {{Forecast}} ({{CF}}) {{Metadata Conventions v1}}.8},
publisher = {{CF Conventions Committee}},
author = {{Eaton}, Brian and {Gregory}, Jonathan and {Drach}, Bob and {Taylor}, Karl and {Hankin}, Steve and {Caron}, John and {Signell}, Rich and {Bentley}, Phil and {Rappa}, Greg and {H{\"o}ck}, Heinke and {Pamment}, Alison and {Juckes}, Martin and {Raspaud}, Martin and {Horne}, Randy and {Whiteaker}, Timothy and {Blodgett}, David and {Zender}, Charlie and {Lee}, Daniel},
month = feb,
year = 2020,
urldate = {2020-07-27},
url = {http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html},
month = sep,
year = 2021,
urldate = {2020-09-10},
url = {http://cfconventions.org/Data/cf-conventions/cf-conventions-1.9/cf-conventions.html},
}

@software{Hassell2:2020,
Expand Down