Skip to content

Commit

Permalink
Add lru_cache to module_available
Browse files Browse the repository at this point in the history
A significant time in
xarray.backends.common.py:AbstractWriteableDataStore.set_variables is
spent on common.py:is_dask_collection as it checks for the presence
of the module dask.

This time becomes significant in the case of many small files.
  • Loading branch information
eivindjahren committed Feb 6, 2024
1 parent f33a632 commit c0b5ef5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions xarray/namedarray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import warnings
from collections.abc import Hashable, Iterable, Iterator, Mapping
from functools import lru_cache
from typing import TYPE_CHECKING, Any, TypeVar, cast

import numpy as np
Expand Down Expand Up @@ -32,6 +33,7 @@
T = TypeVar("T")


@lru_cache
def module_available(module: str) -> bool:
"""Checks whether a module is installed without importing it.
Expand Down

0 comments on commit c0b5ef5

Please sign in to comment.