File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ from datetime import datetime
2
+
1
3
import numpy as np
2
4
import pytest
5
+ from pydantic import BaseModel
3
6
7
+ from numpydantic import NDArray , Shape
4
8
from numpydantic .testing .cases import NumpyCase
5
9
6
10
pytestmark = pytest .mark .numpy
@@ -18,6 +22,29 @@ def test_numpy_dtype(dtype_cases):
18
22
dtype_cases .validate_case ()
19
23
20
24
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
+
21
48
def test_numpy_coercion (model_blank ):
22
49
"""If no other interface matches, we try and coerce to a numpy array"""
23
50
instance = model_blank (array = [1 , 2 , 3 ])
You can’t perform that action at this time.
0 commit comments