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

Accounting for NoneType coordinates in attrs/encoding #359

Merged
merged 3 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ def _get_axis_coord(obj: DataArray | Dataset, key: str) -> list[str]:
)

search_in = set()
if "coordinates" in obj.encoding:
if "coordinates" in obj.encoding and obj.encoding["coordinates"]:
dcherian marked this conversation as resolved.
Show resolved Hide resolved
search_in.update(obj.encoding["coordinates"].split(" "))
if "coordinates" in obj.attrs:
if "coordinates" in obj.attrs and obj.attrs["coordinates"]:
search_in.update(obj.attrs["coordinates"].split(" "))
if not search_in:
search_in = set(obj.coords)
Expand Down Expand Up @@ -1596,7 +1596,7 @@ def get_associated_variable_names(
coords: dict[str, list[str]] = {k: [] for k in keys}
attrs_or_encoding = ChainMap(self._obj[name].attrs, self._obj[name].encoding)

if "coordinates" in attrs_or_encoding:
if "coordinates" in attrs_or_encoding and attrs_or_encoding["coordinates"]:
coords["coordinates"] = attrs_or_encoding["coordinates"].split(" ")

if "cell_measures" in attrs_or_encoding:
Expand Down
8 changes: 8 additions & 0 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ def test_accessor_getattr_and_describe():
assert str(ds_verta.cf) == str(ds_vertb.cf)


def test_accessor_getattr_coordinate_Nonetype():
ds_vert = vert
ds_vert["o3"].encoding["coordinates"] = None
assert ds_vert.o3.cf["latitude"].name == "lat"
ds_vert["lat"].encoding["coordinates"] = None
assert ds_vert.cf["latitude"].name == "lat"


def test_getitem_standard_name():
actual = airds.cf["air_temperature"]
expected = airds["air"]
Expand Down