MCPcopy Index your code
hub / github.com/pydata/xarray / module_available

Function module_available

xarray/namedarray/utils.py:40–65  ·  view source on GitHub ↗

Checks whether a module is installed without importing it. Use this for a lightweight check and lazy imports. Parameters ---------- module : str Name of the module. minversion : str, optional Minimum version of the module Returns ------- available :

(module: str, minversion: str | None = None)

Source from the content-addressed store, hash-verified

38
39@lru_cache
40def module_available(module: str, minversion: str | None = None) -> bool:
41 """Checks whether a module is installed without importing it.
42
43 Use this for a lightweight check and lazy imports.
44
45 Parameters
46 ----------
47 module : str
48 Name of the module.
49 minversion : str, optional
50 Minimum version of the module
51
52 Returns
53 -------
54 available : bool
55 Whether the module is installed.
56 """
57 if importlib.util.find_spec(module) is None:
58 return False
59
60 if minversion is not None:
61 version = importlib.metadata.version(module)
62
63 return Version(version) >= Version(minversion)
64
65 return True
66
67
68def is_dask_collection(x: object) -> TypeGuard[DaskCollection]:

Callers 15

reshape_blockwiseFunction · 0.90
sliding_window_viewFunction · 0.90
strings.pyFile · 0.90
utils.pyFile · 0.90
daskmanager.pyFile · 0.90
shuffleMethod · 0.90
nputils.pyFile · 0.90
fFunction · 0.90
_aggregations.pyFile · 0.90
cumsumMethod · 0.90
cumsumMethod · 0.90
cumsumMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_groupby_scansFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…