Hello,
I would like to use Numpydantic for basic validation checks for xarray.DataArray. I am checking the validity of the coordinates of the array. Some of my datasets have a coordinate of datetime and here it fails.
A simple example:
from pydantic import BaseModel
from numpydantic import NDArray, Shape
import xarray
import numpy
arr = xarray.DataArray(
numpy.ones((3, 2, 1)),
coords={"x": [1, 2, 3], "y": [0.1, numpy.NaN], "t": [numpy.datetime64("2025-02-25"), ]},
dims=["x", "y", "t"]
)
class ArrSchema(BaseModel):
x: NDArray[Shape["3"], int]
y: NDArray[Shape["*"], float]
t: NDArray[Shape["1"], numpy.datetime64]
ArrSchema(**arr.coords) # Raises a ValidationError
ValidationError: 1 validation error for TestingSchema
t
Value error, Invalid dtype! expected <class 'numpy.datetime64'>, got datetime64[D] [type=value_error, input_value=array(['2025-02-25'], dtype='datetime64[D]'), input_type=ndarray]
For further information visit https://errors.pydantic.dev/2.7/v/value_error
I get the same error, if I use ArrSchema directly with a numpy array.
version: v1.6.7
Hello,
I would like to use Numpydantic for basic validation checks for
xarray.DataArray. I am checking the validity of the coordinates of the array. Some of my datasets have a coordinate of datetime and here it fails.A simple example:
I get the same error, if I use
ArrSchemadirectly with a numpy array.version: v1.6.7