Skip to content

Commit 704503e

Browse files
Use explicit type
1 parent 503c039 commit 704503e

File tree

1 file changed

+4
-14
lines changed
  • src/titiler/xarray/titiler/xarray

1 file changed

+4
-14
lines changed

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import attr
77
import numpy
8-
import pandas
98
import xarray
109
from morecantile import TileMatrixSet
1110
from rio_tiler.constants import WEB_MERCATOR_TMS
@@ -134,22 +133,13 @@ def _arrange_dims(da: xarray.DataArray) -> xarray.DataArray:
134133

135134

136135
def _cast_to_type(value, dtype: Any) -> Any:
137-
# Convert dtype to numpy dtype for consistent handling
138-
if hasattr(dtype, "type"):
139-
np_dtype = dtype
140-
else:
141-
np_dtype = numpy.dtype(dtype)
142-
143136
# Explicit datetime64 handling
144-
if np_dtype.kind == "M": # 'M' is numpy's datetime kind
145-
# Always parse as UTC first, then remove timezone - Handles "Z" suffix correctly
146-
parsed_value = pandas.to_datetime(value, utc=True)
147-
# .tz_localize(None) - Removes timezone information, making the datetime "naive"
148-
return parsed_value.tz_localize(None)
137+
if dtype == numpy.datetime64:
138+
return numpy.datetime64(value)
149139

150140
# Explicit timedelta64 handling
151-
elif np_dtype.kind == "m": # 'm' is numpy's timedelta kind
152-
return pandas.to_timedelta(value)
141+
elif dtype == numpy.timedelta64:
142+
return numpy.timedelta64(value)
153143

154144
elif numpy.issubdtype(dtype, numpy.integer):
155145
value = int(value)

0 commit comments

Comments
 (0)