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

Avoid quadratic behaviour when dropping bounds #349

Merged
merged 2 commits into from
Jul 14, 2022
Merged
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
5 changes: 3 additions & 2 deletions cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _apply_single_mapper(mapper):

try:
results = mapper(obj, key)
except KeyError as e:
except (KeyError, ValueError) as e:
if error or "I expected only one." in repr(e):
raise e
else:
Expand Down Expand Up @@ -621,6 +621,7 @@ def _getitem(
"""

obj = accessor._obj
all_bounds = obj.cf.bounds if isinstance(obj, Dataset) else {}
kind = str(type(obj).__name__)
scalar_key = isinstance(key, str)

Expand All @@ -638,7 +639,7 @@ def drop_bounds(names):
if not isinstance(obj, DataArray) and scalar_key:
bounds = set()
for name in names:
bounds.update(obj.cf.bounds.get(name, []))
bounds.update(all_bounds.get(name, []))
names = set(names) - bounds
return names

Expand Down