Skip to content

Commit

Permalink
Fix custom dim selection for string fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Nov 27, 2024
1 parent a04aece commit 9be4f3e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion xpublish_wms/wms/get_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,16 @@ def select_custom_dim(self, da: xr.DataArray) -> xr.DataArray:
for dim, value in self.dim_selectors.items():
if dim in da.coords:
dtype = da[dim].dtype
method=None
if "timedelta" in str(dtype):
value = pd.to_timedelta(value)
elif np.issubdtype(dtype, np.integer):
value = int(value)
method = "nearest"
elif np.issubdtype(dtype, np.floating):
value = float(value)
da = da.sel({dim: value}, method="nearest")
method = "nearest"
da = da.sel({dim: value}, method=method)

# Squeeze single value dimensions
da = da.squeeze()
Expand Down

0 comments on commit 9be4f3e

Please sign in to comment.