Skip to content

Commit b6c75ae

Browse files
Remove _cast_to_type
1 parent 704503e commit b6c75ae

File tree

1 file changed

+3
-21
lines changed
  • src/titiler/xarray/titiler/xarray

1 file changed

+3
-21
lines changed

src/titiler/xarray/titiler/xarray/io.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from urllib.parse import urlparse
55

66
import attr
7-
import numpy
87
import xarray
98
from morecantile import TileMatrixSet
109
from rio_tiler.constants import WEB_MERCATOR_TMS
@@ -132,24 +131,6 @@ def _arrange_dims(da: xarray.DataArray) -> xarray.DataArray:
132131
return da
133132

134133

135-
def _cast_to_type(value, dtype: Any) -> Any:
136-
# Explicit datetime64 handling
137-
if dtype == numpy.datetime64:
138-
return numpy.datetime64(value)
139-
140-
# Explicit timedelta64 handling
141-
elif dtype == numpy.timedelta64:
142-
return numpy.timedelta64(value)
143-
144-
elif numpy.issubdtype(dtype, numpy.integer):
145-
value = int(value)
146-
147-
elif numpy.issubdtype(dtype, numpy.floating):
148-
value = float(value)
149-
150-
return value
151-
152-
153134
def get_variable(
154135
ds: xarray.Dataset,
155136
variable: str,
@@ -175,7 +156,8 @@ def get_variable(
175156
for s in sel:
176157
val: Union[str, slice]
177158
dim, val = s.split("=")
178-
val = _cast_to_type(val, da[dim].dtype)
159+
# cast string to dtype of the dimension
160+
val = da[dim].dtype.type(val)
179161

180162
if dim in _idx:
181163
_idx[dim].append(val)
@@ -210,7 +192,7 @@ class Reader(XarrayReader):
210192
src_path: str = attr.ib()
211193
variable: str = attr.ib()
212194

213-
# xarray.Dataset options
195+
# xarray.Dataset optionsf
214196
opener: Callable[..., xarray.Dataset] = attr.ib(default=xarray_open_dataset)
215197

216198
group: Optional[str] = attr.ib(default=None)

0 commit comments

Comments
 (0)