diff --git a/cf_pandas/accessor.py b/cf_pandas/accessor.py index 899d10c..6b9679f 100644 --- a/cf_pandas/accessor.py +++ b/cf_pandas/accessor.py @@ -161,7 +161,11 @@ def keys(self) -> Set[str]: varnames = list(self.axes) + list(self.coordinates) try: - varnames.extend(list(self.custom_keys)) + # see which custom keys have matched values in object + matched_keys = [ + key for key, val in self.custom_keys.items() if len(val) > 0 + ] + varnames.extend(matched_keys) except ValueError: # don't have criteria defined, then no custom keys to report pass diff --git a/tests/test_accessor.py b/tests/test_accessor.py index dba8455..e594dac 100644 --- a/tests/test_accessor.py +++ b/tests/test_accessor.py @@ -16,6 +16,7 @@ "temp2": { "standard_name": "temp$", }, + "salt2": {"standard_name": "sal$"}, } @@ -73,6 +74,7 @@ def test_match_criteria_key_accessor(): ] assert "X" in df.cf assert "Y" not in df.cf + assert "salt2" not in df.cf @mock.patch("requests.get")