@@ -33,21 +33,40 @@ def test_non_array_raises(self):
33
33
TimedeltaArray ([1 , 2 , 3 ])
34
34
35
35
def test_other_type_raises (self ):
36
- with pytest .raises (ValueError , match = "dtype bool cannot be converted" ):
36
+ msg = "dtype 'bool' is invalid, should be np.timedelta64 dtype"
37
+ with pytest .raises (ValueError , match = msg ):
37
38
TimedeltaArray (np .array ([1 , 2 , 3 ], dtype = "bool" ))
38
39
39
40
def test_incorrect_dtype_raises (self ):
40
- # TODO: why TypeError for 'category' but ValueError for i8?
41
- with pytest .raises (
42
- ValueError , match = r"category cannot be converted to timedelta64\[ns\]"
43
- ):
41
+ msg = "dtype 'category' is invalid, should be np.timedelta64 dtype"
42
+ with pytest .raises (ValueError , match = msg ):
44
43
TimedeltaArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = "category" )
45
44
46
- with pytest .raises (
47
- ValueError , match = r"dtype int64 cannot be converted to timedelta64\[ns\]"
48
- ):
45
+ msg = "dtype 'int64' is invalid, should be np.timedelta64 dtype"
46
+ with pytest .raises (ValueError , match = msg ):
49
47
TimedeltaArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = np .dtype ("int64" ))
50
48
49
+ msg = r"dtype 'datetime64\[ns\]' is invalid, should be np.timedelta64 dtype"
50
+ with pytest .raises (ValueError , match = msg ):
51
+ TimedeltaArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = np .dtype ("M8[ns]" ))
52
+
53
+ msg = (
54
+ r"dtype 'datetime64\[us, UTC\]' is invalid, should be np.timedelta64 dtype"
55
+ )
56
+ with pytest .raises (ValueError , match = msg ):
57
+ TimedeltaArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = "M8[us, UTC]" )
58
+
59
+ msg = "Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'"
60
+ with pytest .raises (ValueError , match = msg ):
61
+ TimedeltaArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = np .dtype ("m8[Y]" ))
62
+
63
+ def test_mismatched_values_dtype_units (self ):
64
+ arr = np .array ([1 , 2 , 3 ], dtype = "m8[s]" )
65
+ dtype = np .dtype ("m8[ns]" )
66
+ msg = r"Values resolution does not match dtype"
67
+ with pytest .raises (ValueError , match = msg ):
68
+ TimedeltaArray (arr , dtype = dtype )
69
+
51
70
def test_copy (self ):
52
71
data = np .array ([1 , 2 , 3 ], dtype = "m8[ns]" )
53
72
arr = TimedeltaArray (data , copy = False )
@@ -58,6 +77,6 @@ def test_copy(self):
58
77
assert arr ._ndarray .base is not data
59
78
60
79
def test_from_sequence_dtype (self ):
61
- msg = "dtype .* object.* cannot be converted to timedelta64"
80
+ msg = "dtype ' object' is invalid, should be np. timedelta64 dtype "
62
81
with pytest .raises (ValueError , match = msg ):
63
82
TimedeltaArray ._from_sequence ([], dtype = object )
0 commit comments