Skip to content

Commit

Permalink
invalidate xindexes cache after in-place coord update
Browse files Browse the repository at this point in the history
  • Loading branch information
benbovy committed Feb 24, 2025
1 parent 1adf33e commit 304a25b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xarray/core/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,17 +801,23 @@ def _update_coords(
original_indexes = dict(self._data.xindexes)
original_indexes.update(indexes)
self._data._indexes = original_indexes
# invalidate xindexes cache
self._data._xindexes = None

def _drop_coords(self, coord_names):
# should drop indexed coordinates only
for name in coord_names:
del self._data._variables[name]
del self._data._indexes[name]
self._data._coord_names.difference_update(coord_names)
# invalidate xindexes cache
self._data._xindexes = None

def __delitem__(self, key: Hashable) -> None:
if key in self:
del self._data[key]
# invalidate xindexes cache
self._data._xindexes = None
else:
raise KeyError(
f"{key!r} is not in coordinate variables {tuple(self.keys())}"
Expand Down

0 comments on commit 304a25b

Please sign in to comment.