From 26186c30f75b138b69dcccbbd1ada0967e9907d9 Mon Sep 17 00:00:00 2001 From: JP Dehollain Date: Fri, 2 May 2025 16:17:42 +1000 Subject: [PATCH 1/2] make fill value empty string for vlen-string dtypes --- xarray/core/dtypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/dtypes.py b/xarray/core/dtypes.py index c959a7f2536..a9ee01485e1 100644 --- a/xarray/core/dtypes.py +++ b/xarray/core/dtypes.py @@ -67,7 +67,7 @@ def maybe_promote(dtype: np.dtype) -> tuple[np.dtype, Any]: # for now, we always promote string dtypes to object for consistency with existing behavior # TODO: refactor this once we have a better way to handle numpy vlen-string dtypes dtype_ = object - fill_value = np.nan + fill_value = "" elif isdtype(dtype, "real floating"): dtype_ = dtype fill_value = np.nan From a9f1192ad35a89e0e44abac1eb933ce872ae20ee Mon Sep 17 00:00:00 2001 From: JP Dehollain Date: Fri, 2 May 2025 16:18:17 +1000 Subject: [PATCH 2/2] support for strings in isnull --- xarray/core/duck_array_ops.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index 96330a64b68..3040cd71dc5 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -157,6 +157,8 @@ def isnull(data): # float types use NaN for null xp = get_array_namespace(data) return xp.isnan(data) + elif xp.isdtype(scalar_type, np.str_): + return data == "" elif dtypes.isdtype(scalar_type, ("bool", "integral"), xp=xp) or ( isinstance(scalar_type, np.dtype) and (