Skip to content

Commit e27668a

Browse files
committed
Cache parse_grid_mapping too
1 parent 3aa7eee commit e27668a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎cf_xarray/accessor.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from xarray import DataArray, Dataset
2828
from xarray.core.groupby import GroupBy
2929
from xarray.core.resample import Resample
30+
from xarray.core.utils import Frozen
3031

3132
try:
3233
from xarray.core.rolling import ( # type:ignore[import-not-found,no-redef,unused-ignore]
@@ -495,6 +496,7 @@ def _get_bounds(obj: DataArray | Dataset, key: Hashable) -> list[Hashable]:
495496
return list(results)
496497

497498

499+
@functools.lru_cache(maxsize=256)
498500
def _parse_grid_mapping_attribute(grid_mapping_attr: str) -> dict[str, list[Hashable]]:
499501
"""
500502
Parse a grid_mapping attribute that may contain multiple grid mappings.
@@ -548,7 +550,7 @@ def _parse_grid_mapping_attribute(grid_mapping_attr: str) -> dict[str, list[Hash
548550
else:
549551
result[gm] = []
550552

551-
return result
553+
return Frozen(result)
552554

553555

554556
def _create_grid_mapping(

0 commit comments

Comments
 (0)