From 2973b1c2b27bc106b0c78bea9a6b8dd7f5ab1b4e Mon Sep 17 00:00:00 2001 From: driphtyio Date: Fri, 10 Jul 2026 14:24:32 -0700 Subject: [PATCH 1/3] docs: fix DataArray.pad constant_values default documentation The docstring claimed constant_values default is 0, but actually defaults to None (which pads with np.nan). Fix to match Dataset.pad. Closes #11373 --- xarray/core/dataarray.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index f8386be63a7..7bccd585590 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -5912,7 +5912,7 @@ def pad( (stat_length,) or int is a shortcut for before = after = statistic length for all axes. Default is ``None``, to use the entire axis. - constant_values : scalar, tuple or mapping of Hashable to tuple, default: 0 + constant_values : scalar, tuple or mapping of Hashable to tuple, default: None Used in 'constant'. The values to set the padded values for each axis. ``{dim_1: (before_1, after_1), ... dim_N: (before_N, after_N)}`` unique @@ -5921,7 +5921,7 @@ def pad( dimension. ``(constant,)`` or ``constant`` is a shortcut for ``before = after = constant`` for all dimensions. - Default is 0. + Default is ``None``, pads with ``np.nan``. end_values : scalar, tuple or mapping of Hashable to tuple, default: 0 Used in 'linear_ramp'. The values used for the ending value of the linear_ramp and that will form the edge of the padded array. From 465d24d0ed0df4a96bfdd9f74869ff6eee6afc62 Mon Sep 17 00:00:00 2001 From: driphtyio Date: Fri, 10 Jul 2026 14:27:26 -0700 Subject: [PATCH 2/3] fix: handle None module in module_available() Add guard for module=None in module_available() to avoid TypeError from find_spec(None). Returns False instead. Closes #11344 --- xarray/namedarray/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xarray/namedarray/utils.py b/xarray/namedarray/utils.py index 3490a76aa8d..64cf4784397 100644 --- a/xarray/namedarray/utils.py +++ b/xarray/namedarray/utils.py @@ -37,15 +37,15 @@ @lru_cache -def module_available(module: str, minversion: str | None = None) -> bool: +def module_available(module: str | None, minversion: str | None = None) -> bool: """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. + module : str or None + Name of the module. If None, returns False. minversion : str, optional Minimum version of the module @@ -54,6 +54,8 @@ def module_available(module: str, minversion: str | None = None) -> bool: available : bool Whether the module is installed. """ + if module is None: + return False if importlib.util.find_spec(module) is None: return False From f30d2d36bc9fb86610144a8402793e0e313a89bb Mon Sep 17 00:00:00 2001 From: driphtyio Date: Fri, 10 Jul 2026 14:29:08 -0700 Subject: [PATCH 3/3] Revert "fix: handle None module in module_available()" This reverts commit 465d24d0ed0df4a96bfdd9f74869ff6eee6afc62. --- xarray/namedarray/utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xarray/namedarray/utils.py b/xarray/namedarray/utils.py index 64cf4784397..3490a76aa8d 100644 --- a/xarray/namedarray/utils.py +++ b/xarray/namedarray/utils.py @@ -37,15 +37,15 @@ @lru_cache -def module_available(module: str | None, minversion: str | None = None) -> bool: +def module_available(module: str, minversion: str | None = None) -> bool: """Checks whether a module is installed without importing it. Use this for a lightweight check and lazy imports. Parameters ---------- - module : str or None - Name of the module. If None, returns False. + module : str + Name of the module. minversion : str, optional Minimum version of the module @@ -54,8 +54,6 @@ def module_available(module: str | None, minversion: str | None = None) -> bool: available : bool Whether the module is installed. """ - if module is None: - return False if importlib.util.find_spec(module) is None: return False