Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: Improve version handling for numbagg #8325

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions xarray/core/rolling_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Generic

import numpy as np
from packaging.version import Version

from xarray.core.computation import apply_ufunc
from xarray.core.options import _get_keep_attrs
Expand All @@ -14,9 +15,9 @@
import numbagg
from numbagg import move_exp_nanmean, move_exp_nansum

has_numbagg = numbagg.__version__
_NUMBAGG_VERSION: Version | None = Version(numbagg.__version__)
except ImportError:
has_numbagg = False
_NUMBAGG_VERSION = None


def _get_alpha(
Expand Down Expand Up @@ -99,17 +100,17 @@ def __init__(
window_type: str = "span",
min_weight: float = 0.0,
):
if has_numbagg is False:
if _NUMBAGG_VERSION is None:
raise ImportError(
"numbagg >= 0.2.1 is required for rolling_exp but currently numbagg is not installed"
)
elif has_numbagg < "0.2.1":
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
elif _NUMBAGG_VERSION < Version("0.2.1"):
raise ImportError(
f"numbagg >= 0.2.1 is required for rolling_exp but currently version {has_numbagg} is installed"
f"numbagg >= 0.2.1 is required for rolling_exp but currently version {_NUMBAGG_VERSION} is installed"
)
elif has_numbagg < "0.3.1" and min_weight > 0:
elif _NUMBAGG_VERSION < Version("0.3.1") and min_weight > 0:
raise ImportError(
f"numbagg >= 0.3.1 is required for `min_weight > 0` but currently version {has_numbagg} is installed"
f"numbagg >= 0.3.1 is required for `min_weight > 0` but currently version {_NUMBAGG_VERSION} is installed"
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
)

self.obj: T_DataWithCoords = obj
Expand Down