Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion xarray/core/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
# 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 (
Expand Down Expand Up @@ -234,7 +236,7 @@

if xp == np:
# numpy currently doesn't have a astype:
return data.astype(dtype, **kwargs)

Check warning on line 239 in xarray/core/duck_array_ops.py

View workflow job for this annotation

GitHub Actions / windows-latest py3.10

invalid value encountered in cast

Check warning on line 239 in xarray/core/duck_array_ops.py

View workflow job for this annotation

GitHub Actions / windows-latest py3.10

invalid value encountered in cast
return xp.astype(data, dtype, **kwargs)


Expand Down
Loading