File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -592,7 +592,17 @@ def to_numpy(
592
592
-------
593
593
numpy.ndarray
594
594
"""
595
- result = np .asarray (self , dtype = dtype )
595
+ if dtype == "datetime64" and self .dtype .kind == "M" :
596
+ # Make sure NaT is not tz_aware
597
+ result = np .array (
598
+ [
599
+ np .datetime64 ("NaT" , "s" ) if isna (x ) else x .tz_localize (None ).asm8
600
+ for x in self
601
+ ],
602
+ dtype = "datetime64[s]" ,
603
+ )
604
+ else :
605
+ result = np .asarray (self , dtype = dtype )
596
606
if copy or na_value is not lib .no_default :
597
607
result = result .copy ()
598
608
if na_value is not lib .no_default :
Original file line number Diff line number Diff line change @@ -1356,3 +1356,11 @@ def test_from_pandas_array(dtype):
1356
1356
result = idx_cls (arr )
1357
1357
expected = idx_cls (data )
1358
1358
tm .assert_index_equal (result , expected )
1359
+
1360
+
1361
+ def test_to_numpy_with_NaT_tz_aware ():
1362
+ # GH#59772
1363
+
1364
+ result = pd .Series (NaT ).dt .tz_localize ("UTC" ).to_numpy ("datetime64" )
1365
+ expected = pd .Series (NaT ).to_numpy ("datetime64" )
1366
+ tm .assert_equal (result , expected )
You can’t perform that action at this time.
0 commit comments