@@ -71,7 +71,7 @@ def test_mixing_naive_tzaware_raises(self, meth):
71
71
def test_from_pandas_array (self ):
72
72
arr = pd .array (np .arange (5 , dtype = np .int64 )) * 3600 * 10 ** 9
73
73
74
- result = DatetimeArray ._from_sequence (arr , freq = "infer" )
74
+ result = DatetimeArray ._from_sequence (arr ). _with_freq ( "infer" )
75
75
76
76
expected = pd .date_range ("1970-01-01" , periods = 5 , freq = "H" )._data
77
77
tm .assert_datetime_array_equal (result , expected )
@@ -162,7 +162,9 @@ def test_cmp_dt64_arraylike_tznaive(self, all_compare_operators):
162
162
163
163
class TestDatetimeArray :
164
164
def test_astype_to_same (self ):
165
- arr = DatetimeArray ._from_sequence (["2000" ], tz = "US/Central" )
165
+ arr = DatetimeArray ._from_sequence (
166
+ ["2000" ], dtype = DatetimeTZDtype (tz = "US/Central" )
167
+ )
166
168
result = arr .astype (DatetimeTZDtype (tz = "US/Central" ), copy = False )
167
169
assert result is arr
168
170
@@ -193,7 +195,9 @@ def test_astype_int(self, dtype):
193
195
tm .assert_numpy_array_equal (result , expected )
194
196
195
197
def test_tz_setter_raises (self ):
196
- arr = DatetimeArray ._from_sequence (["2000" ], tz = "US/Central" )
198
+ arr = DatetimeArray ._from_sequence (
199
+ ["2000" ], dtype = DatetimeTZDtype (tz = "US/Central" )
200
+ )
197
201
with pytest .raises (AttributeError , match = "tz_localize" ):
198
202
arr .tz = "UTC"
199
203
@@ -282,7 +286,8 @@ def test_fillna_preserves_tz(self, method):
282
286
283
287
fill_val = dti [1 ] if method == "pad" else dti [3 ]
284
288
expected = DatetimeArray ._from_sequence (
285
- [dti [0 ], dti [1 ], fill_val , dti [3 ], dti [4 ]], freq = None , tz = "US/Central"
289
+ [dti [0 ], dti [1 ], fill_val , dti [3 ], dti [4 ]],
290
+ dtype = DatetimeTZDtype (tz = "US/Central" ),
286
291
)
287
292
288
293
result = arr .fillna (method = method )
@@ -434,19 +439,24 @@ def test_shift_value_tzawareness_mismatch(self):
434
439
435
440
class TestSequenceToDT64NS :
436
441
def test_tz_dtype_mismatch_raises (self ):
437
- arr = DatetimeArray ._from_sequence (["2000" ], tz = "US/Central" )
442
+ arr = DatetimeArray ._from_sequence (
443
+ ["2000" ], dtype = DatetimeTZDtype (tz = "US/Central" )
444
+ )
438
445
with pytest .raises (TypeError , match = "data is already tz-aware" ):
439
446
sequence_to_dt64ns (arr , dtype = DatetimeTZDtype (tz = "UTC" ))
440
447
441
448
def test_tz_dtype_matches (self ):
442
- arr = DatetimeArray ._from_sequence (["2000" ], tz = "US/Central" )
449
+ arr = DatetimeArray ._from_sequence (
450
+ ["2000" ], dtype = DatetimeTZDtype (tz = "US/Central" )
451
+ )
443
452
result , _ , _ = sequence_to_dt64ns (arr , dtype = DatetimeTZDtype (tz = "US/Central" ))
444
453
tm .assert_numpy_array_equal (arr ._data , result )
445
454
446
455
447
456
class TestReductions :
448
457
@pytest .mark .parametrize ("tz" , [None , "US/Central" ])
449
458
def test_min_max (self , tz ):
459
+ dtype = DatetimeTZDtype (tz = tz ) if tz is not None else np .dtype ("M8[ns]" )
450
460
arr = DatetimeArray ._from_sequence (
451
461
[
452
462
"2000-01-03" ,
@@ -456,7 +466,7 @@ def test_min_max(self, tz):
456
466
"2000-01-05" ,
457
467
"2000-01-04" ,
458
468
],
459
- tz = tz ,
469
+ dtype = dtype ,
460
470
)
461
471
462
472
result = arr .min ()
@@ -476,7 +486,8 @@ def test_min_max(self, tz):
476
486
@pytest .mark .parametrize ("tz" , [None , "US/Central" ])
477
487
@pytest .mark .parametrize ("skipna" , [True , False ])
478
488
def test_min_max_empty (self , skipna , tz ):
479
- arr = DatetimeArray ._from_sequence ([], tz = tz )
489
+ dtype = DatetimeTZDtype (tz = tz ) if tz is not None else np .dtype ("M8[ns]" )
490
+ arr = DatetimeArray ._from_sequence ([], dtype = dtype )
480
491
result = arr .min (skipna = skipna )
481
492
assert result is pd .NaT
482
493
0 commit comments