File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -514,9 +514,6 @@ def astype(self, dtype):
514
514
dtype = np .dtype (dtype )
515
515
516
516
if dtype == np .object_ :
517
- if isnull (self ).any ():
518
- msg = 'DatetimeIndex with NaT cannot be converted to object'
519
- raise ValueError (msg )
520
517
return self .asobject
521
518
return Index .astype (self , dtype )
522
519
@@ -536,6 +533,12 @@ def asobject(self):
536
533
"""
537
534
Convert to Index of datetime objects
538
535
"""
536
+ if isnull (self ).any ():
537
+ msg = 'DatetimeIndex with NaT cannot be converted to object'
538
+ raise ValueError (msg )
539
+ return self ._get_object_index ()
540
+
541
+ def _get_object_index (self ):
539
542
boxed_values = _dt_box_array (self .asi8 , self .offset , self .tz )
540
543
return Index (boxed_values , dtype = object )
541
544
@@ -1013,7 +1016,7 @@ def normalize(self):
1013
1016
return DatetimeIndex (new_values , freq = 'infer' , name = self .name )
1014
1017
1015
1018
def __iter__ (self ):
1016
- return iter (self .asobject )
1019
+ return iter (self ._get_object_index () )
1017
1020
1018
1021
def searchsorted (self , key , side = 'left' ):
1019
1022
if isinstance (key , np .ndarray ):
You can’t perform that action at this time.
0 commit comments