Skip to content

Commit

Permalink
Avoid quadratic behaviour when dropping bounds (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Jul 14, 2022
1 parent b1fe3ff commit 3ddf96a
Showing 1 changed file with 3 additions and 2 deletions.
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

0 comments on commit 3ddf96a

Please sign in to comment.