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 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 (