@@ -6360,9 +6360,6 @@ def astype(
6360
6360
2 2020-01-03
6361
6361
dtype: datetime64[ns]
6362
6362
"""
6363
- if copy and using_copy_on_write ():
6364
- copy = False
6365
-
6366
6363
if is_dict_like (dtype ):
6367
6364
if self .ndim == 1 : # i.e. Series
6368
6365
if len (dtype ) > 1 or self .name not in dtype :
@@ -6371,7 +6368,7 @@ def astype(
6371
6368
"the key in Series dtype mappings."
6372
6369
)
6373
6370
new_type = dtype [self .name ]
6374
- return self .astype (new_type , copy , errors )
6371
+ return self .astype (new_type , errors = errors )
6375
6372
6376
6373
# GH#44417 cast to Series so we can use .iat below, which will be
6377
6374
# robust in case we
@@ -6393,10 +6390,10 @@ def astype(
6393
6390
for i , (col_name , col ) in enumerate (self .items ()):
6394
6391
cdt = dtype_ser .iat [i ]
6395
6392
if isna (cdt ):
6396
- res_col = col .copy (deep = copy )
6393
+ res_col = col .copy (deep = False )
6397
6394
else :
6398
6395
try :
6399
- res_col = col .astype (dtype = cdt , copy = copy , errors = errors )
6396
+ res_col = col .astype (dtype = cdt , errors = errors )
6400
6397
except ValueError as ex :
6401
6398
ex .args = (
6402
6399
f"{ ex } : Error while type casting for column '{ col_name } '" ,
@@ -6410,22 +6407,20 @@ def astype(
6410
6407
if isinstance (dtype , ExtensionDtype ) and all (
6411
6408
arr .dtype == dtype for arr in self ._mgr .arrays
6412
6409
):
6413
- return self .copy (deep = copy )
6410
+ return self .copy (deep = False )
6414
6411
# GH 18099/22869: columnwise conversion to extension dtype
6415
6412
# GH 24704: self.items handles duplicate column names
6416
- results = [
6417
- ser .astype (dtype , copy = copy , errors = errors ) for _ , ser in self .items ()
6418
- ]
6413
+ results = [ser .astype (dtype , errors = errors ) for _ , ser in self .items ()]
6419
6414
6420
6415
else :
6421
6416
# else, only a single dtype is given
6422
- new_data = self ._mgr .astype (dtype = dtype , copy = copy , errors = errors )
6417
+ new_data = self ._mgr .astype (dtype = dtype , errors = errors )
6423
6418
res = self ._constructor_from_mgr (new_data , axes = new_data .axes )
6424
6419
return res .__finalize__ (self , method = "astype" )
6425
6420
6426
6421
# GH 33113: handle empty frame or series
6427
6422
if not results :
6428
- return self .copy (deep = None )
6423
+ return self .copy (deep = False )
6429
6424
6430
6425
# GH 19920: retain column metadata after concat
6431
6426
result = concat (results , axis = 1 , copy = False )
0 commit comments