Skip to content

Commit 3ddf96a

Browse files
authored
Avoid quadratic behaviour when dropping bounds (#349)
1 parent b1fe3ff commit 3ddf96a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cf_xarray/accessor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _apply_single_mapper(mapper):
9999

100100
try:
101101
results = mapper(obj, key)
102-
except KeyError as e:
102+
except (KeyError, ValueError) as e:
103103
if error or "I expected only one." in repr(e):
104104
raise e
105105
else:
@@ -621,6 +621,7 @@ def _getitem(
621621
"""
622622

623623
obj = accessor._obj
624+
all_bounds = obj.cf.bounds if isinstance(obj, Dataset) else {}
624625
kind = str(type(obj).__name__)
625626
scalar_key = isinstance(key, str)
626627

@@ -638,7 +639,7 @@ def drop_bounds(names):
638639
if not isinstance(obj, DataArray) and scalar_key:
639640
bounds = set()
640641
for name in names:
641-
bounds.update(obj.cf.bounds.get(name, []))
642+
bounds.update(all_bounds.get(name, []))
642643
names = set(names) - bounds
643644
return names
644645

0 commit comments

Comments
 (0)