Skip to content

Commit 526c80f

Browse files
internal: Improve version handling for numbagg (#8325)
* internal: Improve version handling for numbagg Uses the approach in #8316, a bit nicer. Only internal. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update xarray/core/rolling_exp.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e1bad52 commit 526c80f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

xarray/core/rolling_exp.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import numbagg
1616
from numbagg import move_exp_nanmean, move_exp_nansum
1717

18-
has_numbagg: Version | None = Version(numbagg.__version__)
18+
_NUMBAGG_VERSION: Version | None = Version(numbagg.__version__)
1919
except ImportError:
20-
has_numbagg = None
20+
_NUMBAGG_VERSION = None
2121

2222

2323
def _get_alpha(
@@ -100,17 +100,17 @@ def __init__(
100100
window_type: str = "span",
101101
min_weight: float = 0.0,
102102
):
103-
if has_numbagg is None:
103+
if _NUMBAGG_VERSION is None:
104104
raise ImportError(
105105
"numbagg >= 0.2.1 is required for rolling_exp but currently numbagg is not installed"
106106
)
107-
elif has_numbagg < Version("0.2.1"):
107+
elif _NUMBAGG_VERSION < Version("0.2.1"):
108108
raise ImportError(
109-
f"numbagg >= 0.2.1 is required for `rolling_exp` but currently version {has_numbagg} is installed"
109+
f"numbagg >= 0.2.1 is required for rolling_exp but currently version {_NUMBAGG_VERSION} is installed"
110110
)
111-
elif has_numbagg < Version("0.3.1") and min_weight > 0:
111+
elif _NUMBAGG_VERSION < Version("0.3.1") and min_weight > 0:
112112
raise ImportError(
113-
f"numbagg >= 0.3.1 is required for `min_weight > 0` within `.rolling_exp` but currently version {has_numbagg} is installed"
113+
f"numbagg >= 0.3.1 is required for `min_weight > 0` within `.rolling_exp` but currently version {_NUMBAGG_VERSION} is installed"
114114
)
115115

116116
self.obj: T_DataWithCoords = obj
@@ -211,9 +211,9 @@ def std(self) -> T_DataWithCoords:
211211
Dimensions without coordinates: x
212212
"""
213213

214-
if has_numbagg is None or has_numbagg < Version("0.4.0"):
214+
if _NUMBAGG_VERSION is None or _NUMBAGG_VERSION < Version("0.4.0"):
215215
raise ImportError(
216-
f"numbagg >= 0.4.0 is required for rolling_exp().std(), currently {has_numbagg} is installed"
216+
f"numbagg >= 0.4.0 is required for rolling_exp().std(), currently {_NUMBAGG_VERSION} is installed"
217217
)
218218
dim_order = self.obj.dims
219219

@@ -243,9 +243,9 @@ def var(self) -> T_DataWithCoords:
243243
Dimensions without coordinates: x
244244
"""
245245

246-
if has_numbagg is None or has_numbagg < Version("0.4.0"):
246+
if _NUMBAGG_VERSION is None or _NUMBAGG_VERSION < Version("0.4.0"):
247247
raise ImportError(
248-
f"numbagg >= 0.4.0 is required for rolling_exp().var(), currently {has_numbagg} is installed"
248+
f"numbagg >= 0.4.0 is required for rolling_exp().var(), currently {_NUMBAGG_VERSION} is installed"
249249
)
250250
dim_order = self.obj.dims
251251

@@ -275,9 +275,9 @@ def cov(self, other: T_DataWithCoords) -> T_DataWithCoords:
275275
Dimensions without coordinates: x
276276
"""
277277

278-
if has_numbagg is None or has_numbagg < Version("0.4.0"):
278+
if _NUMBAGG_VERSION is None or _NUMBAGG_VERSION < Version("0.4.0"):
279279
raise ImportError(
280-
f"numbagg >= 0.4.0 is required for rolling_exp().cov(), currently {has_numbagg} is installed"
280+
f"numbagg >= 0.4.0 is required for rolling_exp().cov(), currently {_NUMBAGG_VERSION} is installed"
281281
)
282282
dim_order = self.obj.dims
283283

@@ -308,9 +308,9 @@ def corr(self, other: T_DataWithCoords) -> T_DataWithCoords:
308308
Dimensions without coordinates: x
309309
"""
310310

311-
if has_numbagg is None or has_numbagg < Version("0.4.0"):
311+
if _NUMBAGG_VERSION is None or _NUMBAGG_VERSION < Version("0.4.0"):
312312
raise ImportError(
313-
f"numbagg >= 0.4.0 is required for rolling_exp().cov(), currently {has_numbagg} is installed"
313+
f"numbagg >= 0.4.0 is required for rolling_exp().cov(), currently {_NUMBAGG_VERSION} is installed"
314314
)
315315
dim_order = self.obj.dims
316316

0 commit comments

Comments
 (0)