Skip to content

Commit d763d8f

Browse files
add correctly failing tests
1 parent 700cd97 commit d763d8f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_interface/test_numpy.py

+27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
from datetime import datetime
2+
13
import numpy as np
24
import pytest
5+
from pydantic import BaseModel
36

7+
from numpydantic import NDArray, Shape
48
from numpydantic.testing.cases import NumpyCase
59

610
pytestmark = pytest.mark.numpy
@@ -18,6 +22,29 @@ def test_numpy_dtype(dtype_cases):
1822
dtype_cases.validate_case()
1923

2024

25+
@pytest.mark.dtype
26+
def test_numpy_datetime64():
27+
"""
28+
Special testing for datetime64, since it's a numpy-specific thing,
29+
and requires special handling in the other interfaces.
30+
31+
Typically, we expect that generic type annotation to be a `datetime.datetime`,
32+
but it should also be possible to use a numpy.datetime64 type when doing
33+
numpy validation.
34+
35+
So this test is just the simplest regression test to make sure we can use datetime64
36+
"""
37+
arr = np.array([np.datetime64(datetime.now())], dtype=np.datetime64)
38+
39+
annotation = NDArray[Shape["*"], np.datetime64]
40+
_ = annotation(arr)
41+
42+
class MyModel(BaseModel):
43+
array: annotation
44+
45+
_ = MyModel(array=arr)
46+
47+
2148
def test_numpy_coercion(model_blank):
2249
"""If no other interface matches, we try and coerce to a numpy array"""
2350
instance = model_blank(array=[1, 2, 3])

0 commit comments

Comments
 (0)