Skip to content

Commit

Permalink
Fix custom dim selection for string fields (#103)
Browse files Browse the repository at this point in the history
* Fix custom dim selection for string fields

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
mpiannucci and pre-commit-ci[bot] authored Nov 27, 2024
1 parent a04aece commit 0739a37
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 0739a37

Please sign in to comment.