Skip to content

Update filter_by_attrs to use 'variables' instead of 'data_vars' #3247

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

Merged
merged 5 commits into from
Aug 23, 2019
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
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5139,7 +5139,7 @@ def filter_by_attrs(self, **kwargs):

""" # noqa
selection = []
for var_name, variable in self.data_vars.items():
for var_name, variable in self.variables.items():
has_value_flag = False
for attr_name, pattern in kwargs.items():
attr_value = variable.attrs.get(attr_name)
Expand Down
7 changes: 6 additions & 1 deletion xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4920,7 +4920,7 @@ def test_filter_by_attrs(self):
"temperature_10": (["t"], [0], temp10),
"precipitation": (["t"], [0], precip),
},
coords={"time": (["t"], [0], dict(axis="T"))},
coords={"time": (["t"], [0], dict(axis="T", long_name="time_in_seconds"))},
)

# Test return empty Dataset.
Expand All @@ -4934,6 +4934,11 @@ def test_filter_by_attrs(self):

assert_equal(new_ds["precipitation"], ds["precipitation"])

# Test filter coordinates
new_ds = ds.filter_by_attrs(long_name="time_in_seconds")
assert new_ds["time"].long_name == "time_in_seconds"
assert not bool(new_ds.data_vars)

# Test return more than one DataArray.
new_ds = ds.filter_by_attrs(standard_name="air_potential_temperature")
assert len(new_ds.data_vars) == 2
Expand Down