Skip to content

Commit 5f7e385

Browse files
authored
Fix cell measures parser (#112)
* break tests * fix cell_measures parser
1 parent 4249cf1 commit 5f7e385

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

cf_xarray/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def _get_measure(da: Union[DataArray, Dataset], key: str) -> List[str]:
367367
)
368368

369369
attr = da.attrs["cell_measures"]
370-
strings = [s.strip() for s in attr.strip().split(":")]
370+
strings = [s for scolons in attr.split(":") for s in scolons.split()]
371371
if len(strings) % 2 != 0:
372372
raise ValueError(f"attrs['cell_measures'] = {attr!r} is malformed.")
373373
measures = dict(zip(strings[slice(0, None, 2)], strings[slice(1, None, 2)]))

cf_xarray/tests/test_accessor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ def test_coordinates():
5353

5454

5555
def test_cell_measures():
56+
da = airds["air"].copy()
57+
da.attrs["cell_measures"] += " dummy: dummy"
5658
expected = dict(area=["cell_area"])
57-
actual = airds["air"].cf.cell_measures
59+
actual = da.cf.cell_measures
5860
assert actual == expected
5961

6062
with pytest.raises(AssertionError, match=r"this only works with DataArrays"):

0 commit comments

Comments
 (0)