@@ -16,34 +16,6 @@ def test_from_sequence_invalid_type(self):
16
16
with pytest .raises (TypeError , match = "Cannot create a DatetimeArray" ):
17
17
DatetimeArray ._from_sequence (mi , dtype = "M8[ns]" )
18
18
19
- def test_only_1dim_accepted (self ):
20
- arr = np .array ([0 , 1 , 2 , 3 ], dtype = "M8[h]" ).astype ("M8[ns]" )
21
-
22
- depr_msg = "DatetimeArray.__init__ is deprecated"
23
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
24
- with pytest .raises (ValueError , match = "Only 1-dimensional" ):
25
- # 3-dim, we allow 2D to sneak in for ops purposes GH#29853
26
- DatetimeArray (arr .reshape (2 , 2 , 1 ))
27
-
28
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
29
- with pytest .raises (ValueError , match = "Only 1-dimensional" ):
30
- # 0-dim
31
- DatetimeArray (arr [[0 ]].squeeze ())
32
-
33
- def test_freq_validation (self ):
34
- # GH#24623 check that invalid instances cannot be created with the
35
- # public constructor
36
- arr = np .arange (5 , dtype = np .int64 ) * 3600 * 10 ** 9
37
-
38
- msg = (
39
- "Inferred frequency h from passed values does not "
40
- "conform to passed frequency W-SUN"
41
- )
42
- depr_msg = "DatetimeArray.__init__ is deprecated"
43
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
44
- with pytest .raises (ValueError , match = msg ):
45
- DatetimeArray (arr , freq = "W" )
46
-
47
19
@pytest .mark .parametrize (
48
20
"meth" ,
49
21
[
@@ -76,42 +48,9 @@ def test_from_pandas_array(self):
76
48
expected = pd .date_range ("1970-01-01" , periods = 5 , freq = "h" )._data
77
49
tm .assert_datetime_array_equal (result , expected )
78
50
79
- def test_mismatched_timezone_raises (self ):
80
- depr_msg = "DatetimeArray.__init__ is deprecated"
81
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
82
- arr = DatetimeArray (
83
- np .array (["2000-01-01T06:00:00" ], dtype = "M8[ns]" ),
84
- dtype = DatetimeTZDtype (tz = "US/Central" ),
85
- )
86
- dtype = DatetimeTZDtype (tz = "US/Eastern" )
87
- msg = r"dtype=datetime64\[ns.*\] does not match data dtype datetime64\[ns.*\]"
88
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
89
- with pytest .raises (TypeError , match = msg ):
90
- DatetimeArray (arr , dtype = dtype )
91
-
92
- # also with mismatched tzawareness
93
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
94
- with pytest .raises (TypeError , match = msg ):
95
- DatetimeArray (arr , dtype = np .dtype ("M8[ns]" ))
96
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
97
- with pytest .raises (TypeError , match = msg ):
98
- DatetimeArray (arr .tz_localize (None ), dtype = arr .dtype )
99
-
100
- def test_non_array_raises (self ):
101
- depr_msg = "DatetimeArray.__init__ is deprecated"
102
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
103
- with pytest .raises (ValueError , match = "list" ):
104
- DatetimeArray ([1 , 2 , 3 ])
105
-
106
51
def test_bool_dtype_raises (self ):
107
52
arr = np .array ([1 , 2 , 3 ], dtype = "bool" )
108
53
109
- depr_msg = "DatetimeArray.__init__ is deprecated"
110
- msg = "Unexpected value for 'dtype': 'bool'. Must be"
111
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
112
- with pytest .raises (ValueError , match = msg ):
113
- DatetimeArray (arr )
114
-
115
54
msg = r"dtype bool cannot be converted to datetime64\[ns\]"
116
55
with pytest .raises (TypeError , match = msg ):
117
56
DatetimeArray ._from_sequence (arr , dtype = "M8[ns]" )
@@ -122,41 +61,6 @@ def test_bool_dtype_raises(self):
122
61
with pytest .raises (TypeError , match = msg ):
123
62
pd .to_datetime (arr )
124
63
125
- def test_incorrect_dtype_raises (self ):
126
- depr_msg = "DatetimeArray.__init__ is deprecated"
127
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
128
- with pytest .raises (ValueError , match = "Unexpected value for 'dtype'." ):
129
- DatetimeArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = "category" )
130
-
131
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
132
- with pytest .raises (ValueError , match = "Unexpected value for 'dtype'." ):
133
- DatetimeArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = "m8[s]" )
134
-
135
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
136
- with pytest .raises (ValueError , match = "Unexpected value for 'dtype'." ):
137
- DatetimeArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), dtype = "M8[D]" )
138
-
139
- def test_mismatched_values_dtype_units (self ):
140
- arr = np .array ([1 , 2 , 3 ], dtype = "M8[s]" )
141
- dtype = np .dtype ("M8[ns]" )
142
- msg = "Values resolution does not match dtype."
143
- depr_msg = "DatetimeArray.__init__ is deprecated"
144
-
145
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
146
- with pytest .raises (ValueError , match = msg ):
147
- DatetimeArray (arr , dtype = dtype )
148
-
149
- dtype2 = DatetimeTZDtype (tz = "UTC" , unit = "ns" )
150
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
151
- with pytest .raises (ValueError , match = msg ):
152
- DatetimeArray (arr , dtype = dtype2 )
153
-
154
- def test_freq_infer_raises (self ):
155
- depr_msg = "DatetimeArray.__init__ is deprecated"
156
- with tm .assert_produces_warning (FutureWarning , match = depr_msg ):
157
- with pytest .raises (ValueError , match = "Frequency inference" ):
158
- DatetimeArray (np .array ([1 , 2 , 3 ], dtype = "i8" ), freq = "infer" )
159
-
160
64
def test_copy (self ):
161
65
data = np .array ([1 , 2 , 3 ], dtype = "M8[ns]" )
162
66
arr = DatetimeArray ._from_sequence (data , copy = False )
0 commit comments