@@ -552,10 +552,10 @@ def f(m, v, i):
552
552
553
553
return self .split_and_operate (None , f , False )
554
554
555
- def astype (self , dtype , copy = False , errors = "raise" , values = None , ** kwargs ):
556
- return self ._astype (dtype , copy = copy , errors = errors , values = values , ** kwargs )
555
+ def astype (self , dtype , copy = False , errors = "raise" , ** kwargs ):
556
+ return self ._astype (dtype , copy = copy , errors = errors , ** kwargs )
557
557
558
- def _astype (self , dtype , copy = False , errors = "raise" , values = None , ** kwargs ):
558
+ def _astype (self , dtype , copy = False , errors = "raise" , ** kwargs ):
559
559
"""Coerce to the new type
560
560
561
561
Parameters
@@ -616,42 +616,39 @@ def _astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):
616
616
return self .copy ()
617
617
return self
618
618
619
- if values is None :
620
- try :
621
- # force the copy here
622
- if self .is_extension :
623
- values = self .values .astype (dtype )
624
- else :
625
- if issubclass (dtype .type , str ):
626
-
627
- # use native type formatting for datetime/tz/timedelta
628
- if self .is_datelike :
629
- values = self .to_native_types ()
619
+ try :
620
+ # force the copy here
621
+ if self .is_extension :
622
+ values = self .values .astype (dtype )
623
+ else :
624
+ if issubclass (dtype .type , str ):
630
625
631
- # astype formatting
632
- else :
633
- values = self .get_values ()
626
+ # use native type formatting for datetime/tz/timedelta
627
+ if self . is_datelike :
628
+ values = self .to_native_types ()
634
629
630
+ # astype formatting
635
631
else :
636
- values = self .get_values (dtype = dtype )
632
+ values = self .get_values ()
637
633
638
- # _astype_nansafe works fine with 1-d only
639
- vals1d = values .ravel ()
640
- values = astype_nansafe (vals1d , dtype , copy = True , ** kwargs )
634
+ else :
635
+ values = self .get_values (dtype = dtype )
641
636
642
- # TODO(extension)
643
- # should we make this attribute?
644
- if isinstance (values , np .ndarray ):
645
- values = values .reshape (self .shape )
637
+ # _astype_nansafe works fine with 1-d only
638
+ vals1d = values .ravel ()
639
+ values = astype_nansafe (vals1d , dtype , copy = True , ** kwargs )
646
640
647
- except Exception :
648
- # e.g. astype_nansafe can fail on object-dtype of strings
649
- # trying to convert to float
650
- if errors == "raise" :
651
- raise
652
- newb = self .copy () if copy else self
653
- else :
654
- newb = make_block (values , placement = self .mgr_locs , ndim = self .ndim )
641
+ # TODO(extension)
642
+ # should we make this attribute?
643
+ if isinstance (values , np .ndarray ):
644
+ values = values .reshape (self .shape )
645
+
646
+ except Exception :
647
+ # e.g. astype_nansafe can fail on object-dtype of strings
648
+ # trying to convert to float
649
+ if errors == "raise" :
650
+ raise
651
+ newb = self .copy () if copy else self
655
652
else :
656
653
newb = make_block (values , placement = self .mgr_locs , ndim = self .ndim )
657
654
0 commit comments