@@ -241,14 +241,21 @@ def test_insert_float_index(
241241 @pytest .mark .parametrize (
242242 "fill_val,exp_dtype" ,
243243 [
244- (pd .Timestamp ("2012-01-01" ), "datetime64[ns]" ),
245- (pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ), "datetime64[ns, US/Eastern]" ),
244+ (pd .Timestamp ("2012-01-01" ).as_unit ("s" ), "datetime64[ns]" ),
245+ (
246+ pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ).as_unit ("s" ),
247+ "datetime64[ns, US/Eastern]" ,
248+ ),
246249 ],
247250 ids = ["datetime64" , "datetime64tz" ],
248251 )
249252 @pytest .mark .parametrize (
250253 "insert_value" ,
251- [pd .Timestamp ("2012-01-01" ), pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" ), 1 ],
254+ [
255+ pd .Timestamp ("2012-01-01" ).as_unit ("s" ),
256+ pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" ).as_unit ("s" ),
257+ 1 ,
258+ ],
252259 )
253260 def test_insert_index_datetimes (self , fill_val , exp_dtype , insert_value ):
254261 obj = pd .DatetimeIndex (
@@ -264,13 +271,13 @@ def test_insert_index_datetimes(self, fill_val, exp_dtype, insert_value):
264271
265272 if fill_val .tz :
266273 # mismatched tzawareness
267- ts = pd .Timestamp ("2012-01-01" )
274+ ts = pd .Timestamp ("2012-01-01" ). as_unit ( "s" )
268275 result = obj .insert (1 , ts )
269276 expected = obj .astype (object ).insert (1 , ts )
270277 assert expected .dtype == object
271278 tm .assert_index_equal (result , expected )
272279
273- ts = pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" )
280+ ts = pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" ). as_unit ( "s" )
274281 result = obj .insert (1 , ts )
275282 # once deprecation is enforced:
276283 expected = obj .insert (1 , ts .tz_convert (obj .dtype .tz ))
@@ -279,7 +286,7 @@ def test_insert_index_datetimes(self, fill_val, exp_dtype, insert_value):
279286
280287 else :
281288 # mismatched tzawareness
282- ts = pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" )
289+ ts = pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" ). as_unit ( "s" )
283290 result = obj .insert (1 , ts )
284291 expected = obj .astype (object ).insert (1 , ts )
285292 assert expected .dtype == object
@@ -302,7 +309,7 @@ def test_insert_index_timedelta64(self):
302309 obj , pd .Timedelta ("10 day" ), exp , "timedelta64[ns]"
303310 )
304311
305- for item in [pd .Timestamp ("2012-01-01" ), 1 ]:
312+ for item in [pd .Timestamp ("2012-01-01" ). as_unit ( "s" ) , 1 ]:
306313 result = obj .insert (1 , item )
307314 expected = obj .astype (object ).insert (1 , item )
308315 assert expected .dtype == object
@@ -312,7 +319,11 @@ def test_insert_index_timedelta64(self):
312319 "insert, coerced_val, coerced_dtype" ,
313320 [
314321 (pd .Period ("2012-01" , freq = "M" ), "2012-01" , "period[M]" ),
315- (pd .Timestamp ("2012-01-01" ), pd .Timestamp ("2012-01-01" ), object ),
322+ (
323+ pd .Timestamp ("2012-01-01" ).as_unit ("s" ),
324+ pd .Timestamp ("2012-01-01" ).as_unit ("s" ),
325+ object ,
326+ ),
316327 (1 , 1 , object ),
317328 ("x" , "x" , object ),
318329 ],
@@ -451,8 +462,8 @@ def test_where_series_bool(self, index_or_series, fill_val, exp_dtype):
451462 @pytest .mark .parametrize (
452463 "fill_val,exp_dtype" ,
453464 [
454- (pd .Timestamp ("2012-01-01" ), "datetime64[ns]" ),
455- (pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ), object ),
465+ (pd .Timestamp ("2012-01-01" ). as_unit ( "s" ) , "datetime64[ns]" ),
466+ (pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ). as_unit ( "s" ) , object ),
456467 ],
457468 ids = ["datetime64" , "datetime64tz" ],
458469 )
@@ -596,8 +607,8 @@ def test_fillna_complex128(self, index_or_series, fill_val, fill_dtype):
596607 @pytest .mark .parametrize (
597608 "fill_val,fill_dtype" ,
598609 [
599- (pd .Timestamp ("2012-01-01" ), "datetime64[s]" ),
600- (pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ), object ),
610+ (pd .Timestamp ("2012-01-01" ). as_unit ( "s" ) , "datetime64[s]" ),
611+ (pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ). as_unit ( "s" ) , object ),
601612 (1 , object ),
602613 ("x" , object ),
603614 ],
@@ -607,31 +618,37 @@ def test_fillna_datetime(self, index_or_series, fill_val, fill_dtype):
607618 klass = index_or_series
608619 obj = klass (
609620 [
610- pd .Timestamp ("2011-01-01" ),
621+ pd .Timestamp ("2011-01-01" ). as_unit ( "s" ) ,
611622 pd .NaT ,
612- pd .Timestamp ("2011-01-03" ),
613- pd .Timestamp ("2011-01-04" ),
623+ pd .Timestamp ("2011-01-03" ). as_unit ( "s" ) ,
624+ pd .Timestamp ("2011-01-04" ). as_unit ( "s" ) ,
614625 ]
615626 )
616627 assert obj .dtype == "datetime64[s]"
617628
618629 exp = klass (
619630 [
620- pd .Timestamp ("2011-01-01" ),
631+ pd .Timestamp ("2011-01-01" ). as_unit ( "s" ) ,
621632 fill_val ,
622- pd .Timestamp ("2011-01-03" ),
623- pd .Timestamp ("2011-01-04" ),
633+ pd .Timestamp ("2011-01-03" ). as_unit ( "s" ) ,
634+ pd .Timestamp ("2011-01-04" ). as_unit ( "s" ) ,
624635 ]
625636 )
626637 self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
627638
628639 @pytest .mark .parametrize (
629640 "fill_val,fill_dtype" ,
630641 [
631- (pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ), "datetime64[s, US/Eastern]" ),
632- (pd .Timestamp ("2012-01-01" ), object ),
642+ (
643+ pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ).as_unit ("s" ),
644+ "datetime64[s, US/Eastern]" ,
645+ ),
646+ (pd .Timestamp ("2012-01-01" ).as_unit ("s" ), object ),
633647 # pre-2.0 with a mismatched tz we would get object result
634- (pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" ), "datetime64[s, US/Eastern]" ),
648+ (
649+ pd .Timestamp ("2012-01-01" , tz = "Asia/Tokyo" ).as_unit ("s" ),
650+ "datetime64[s, US/Eastern]" ,
651+ ),
635652 (1 , object ),
636653 ("x" , object ),
637654 ],
@@ -642,10 +659,10 @@ def test_fillna_datetime64tz(self, index_or_series, fill_val, fill_dtype):
642659
643660 obj = klass (
644661 [
645- pd .Timestamp ("2011-01-01" , tz = tz ),
662+ pd .Timestamp ("2011-01-01" , tz = tz ). as_unit ( "s" ) ,
646663 pd .NaT ,
647- pd .Timestamp ("2011-01-03" , tz = tz ),
648- pd .Timestamp ("2011-01-04" , tz = tz ),
664+ pd .Timestamp ("2011-01-03" , tz = tz ). as_unit ( "s" ) ,
665+ pd .Timestamp ("2011-01-04" , tz = tz ). as_unit ( "s" ) ,
649666 ]
650667 )
651668 assert obj .dtype == "datetime64[s, US/Eastern]"
@@ -656,10 +673,10 @@ def test_fillna_datetime64tz(self, index_or_series, fill_val, fill_dtype):
656673 fv = fill_val .tz_convert (tz )
657674 exp = klass (
658675 [
659- pd .Timestamp ("2011-01-01" , tz = tz ),
676+ pd .Timestamp ("2011-01-01" , tz = tz ). as_unit ( "s" ) ,
660677 fv ,
661- pd .Timestamp ("2011-01-03" , tz = tz ),
662- pd .Timestamp ("2011-01-04" , tz = tz ),
678+ pd .Timestamp ("2011-01-03" , tz = tz ). as_unit ( "s" ) ,
679+ pd .Timestamp ("2011-01-04" , tz = tz ). as_unit ( "s" ) ,
663680 ]
664681 )
665682 self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
@@ -672,8 +689,8 @@ def test_fillna_datetime64tz(self, index_or_series, fill_val, fill_dtype):
672689 1 + 1j ,
673690 True ,
674691 pd .Interval (1 , 2 , closed = "left" ),
675- pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ),
676- pd .Timestamp ("2012-01-01" ),
692+ pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ). as_unit ( "s" ) ,
693+ pd .Timestamp ("2012-01-01" ). as_unit ( "s" ) ,
677694 pd .Timedelta (days = 1 ),
678695 pd .Period ("2016-01-01" , "D" ),
679696 ],
@@ -716,8 +733,8 @@ def test_fillna_series_timedelta64(self):
716733 1 + 1j ,
717734 True ,
718735 pd .Interval (1 , 2 , closed = "left" ),
719- pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ),
720- pd .Timestamp ("2012-01-01" ),
736+ pd .Timestamp ("2012-01-01" , tz = "US/Eastern" ). as_unit ( "s" ) ,
737+ pd .Timestamp ("2012-01-01" ). as_unit ( "s" ) ,
721738 pd .Timedelta (days = 1 ),
722739 pd .Period ("2016-01-01" , "W" ),
723740 ],
@@ -751,14 +768,17 @@ class TestReplaceSeriesCoercion(CoercionBase):
751768 rep ["float64" ] = [1.1 , 2.2 ]
752769 rep ["complex128" ] = [1 + 1j , 2 + 2j ]
753770 rep ["bool" ] = [True , False ]
754- rep ["datetime64[ns]" ] = [pd .Timestamp ("2011-01-01" ), pd .Timestamp ("2011-01-03" )]
771+ rep ["datetime64[ns]" ] = [
772+ pd .Timestamp ("2011-01-01" ).as_unit ("s" ),
773+ pd .Timestamp ("2011-01-03" ).as_unit ("s" ),
774+ ]
755775
756776 for tz in ["UTC" , "US/Eastern" ]:
757777 # to test tz => different tz replacement
758778 key = f"datetime64[ns, { tz } ]"
759779 rep [key ] = [
760- pd .Timestamp ("2011-01-01" , tz = tz ),
761- pd .Timestamp ("2011-01-03" , tz = tz ),
780+ pd .Timestamp ("2011-01-01" , tz = tz ). as_unit ( "s" ) ,
781+ pd .Timestamp ("2011-01-03" , tz = tz ). as_unit ( "s" ) ,
762782 ]
763783
764784 rep ["timedelta64[ns]" ] = [pd .Timedelta ("1 day" ), pd .Timedelta ("2 day" )]
0 commit comments