@@ -544,63 +544,36 @@ def test_to_datetime_unparseable_ignore(self):
544
544
545
545
@td .skip_if_windows # `tm.set_timezone` does not work in windows
546
546
def test_to_datetime_now (self ):
547
- # See GH#18666
547
+ # See GH#18705, to_datetime("now") matches Timestamp.now()
548
548
with tm .set_timezone ("US/Eastern" ):
549
- npnow = np . datetime64 ( " now" ). astype ( "datetime64[ns]" )
549
+ tsnow = Timestamp . now ( )
550
550
pdnow = to_datetime ("now" )
551
551
pdnow2 = to_datetime (["now" ])[0 ]
552
552
553
553
# These should all be equal with infinite perf; this gives
554
- # a generous margin of 10 seconds
555
- assert abs (pdnow .value - npnow . astype ( np . int64 )) < 1e10
556
- assert abs (pdnow2 .value - npnow . astype ( np . int64 )) < 1e10
554
+ # a generous margin of 1 seconds
555
+ assert abs (pdnow .value - tsnow . value ) < 1e9
556
+ assert abs (pdnow2 .value - tsnow . value ) < 1e9
557
557
558
558
assert pdnow .tzinfo is None
559
559
assert pdnow2 .tzinfo is None
560
560
561
561
@td .skip_if_windows # `tm.set_timezone` does not work in windows
562
562
def test_to_datetime_today (self ):
563
- # See GH#18666
564
- # Test with one timezone far ahead of UTC and another far behind, so
565
- # one of these will _almost_ always be in a different day from UTC.
566
- # Unfortunately this test between 12 and 1 AM Samoa time
567
- # this both of these timezones _and_ UTC will all be in the same day,
568
- # so this test will not detect the regression introduced in #18666.
569
- with tm .set_timezone ("Pacific/Auckland" ): # 12-13 hours ahead of UTC
570
- nptoday = np .datetime64 ("today" ).astype ("datetime64[ns]" ).astype (np .int64 )
571
- pdtoday = to_datetime ("today" )
572
- pdtoday2 = to_datetime (["today" ])[0 ]
573
-
574
- tstoday = Timestamp ("today" )
575
- tstoday2 = Timestamp .today ()
576
-
577
- # These should all be equal with infinite perf; this gives
578
- # a generous margin of 10 seconds
579
- assert abs (pdtoday .normalize ().value - nptoday ) < 1e10
580
- assert abs (pdtoday2 .normalize ().value - nptoday ) < 1e10
581
- assert abs (pdtoday .value - tstoday .value ) < 1e10
582
- assert abs (pdtoday .value - tstoday2 .value ) < 1e10
583
-
584
- assert pdtoday .tzinfo is None
585
- assert pdtoday2 .tzinfo is None
586
-
587
- with tm .set_timezone ("US/Samoa" ): # 11 hours behind UTC
588
- nptoday = np .datetime64 ("today" ).astype ("datetime64[ns]" ).astype (np .int64 )
563
+ # See GH##18705, to_datetime("today") matches Timestamp.today()
564
+ with tm .set_timezone ("Pacific/Auckland" ):
565
+ tstoday = Timestamp .today ()
589
566
pdtoday = to_datetime ("today" )
590
567
pdtoday2 = to_datetime (["today" ])[0 ]
591
568
592
569
# These should all be equal with infinite perf; this gives
593
- # a generous margin of 10 seconds
594
- assert abs (pdtoday .normalize (). value - nptoday ) < 1e10
595
- assert abs (pdtoday2 .normalize (). value - nptoday ) < 1e10
570
+ # a generous margin of 1 seconds
571
+ assert abs (pdtoday .value - tstoday . value ) < 1e9
572
+ assert abs (pdtoday2 .value - tstoday . value ) < 1e9
596
573
597
574
assert pdtoday .tzinfo is None
598
575
assert pdtoday2 .tzinfo is None
599
576
600
- def test_to_datetime_today_now_unicode_bytes (self ):
601
- to_datetime (["now" ])
602
- to_datetime (["today" ])
603
-
604
577
@pytest .mark .parametrize ("cache" , [True , False ])
605
578
def test_to_datetime_dt64s (self , cache ):
606
579
in_bound_dts = [np .datetime64 ("2000-01-01" ), np .datetime64 ("2000-01-02" )]
0 commit comments