Skip to content

CoW: Enforce some deprecations on the block level #57253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10744,7 +10744,6 @@ def _series_round(ser: Series, decimals: int) -> Series:
# type "Union[int, integer[Any]]"; expected "int"
new_mgr = self._mgr.round(
decimals=decimals, # type: ignore[arg-type]
using_cow=using_copy_on_write(),
)
return self._constructor_from_mgr(new_mgr, axes=new_mgr.axes).__finalize__(
self, method="round"
Expand Down
19 changes: 7 additions & 12 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6360,9 +6360,6 @@ def astype(
2 2020-01-03
dtype: datetime64[ns]
"""
if copy and using_copy_on_write():
copy = False

if is_dict_like(dtype):
if self.ndim == 1: # i.e. Series
if len(dtype) > 1 or self.name not in dtype:
Expand All @@ -6371,7 +6368,7 @@ def astype(
"the key in Series dtype mappings."
)
new_type = dtype[self.name]
return self.astype(new_type, copy, errors)
return self.astype(new_type, errors=errors)

# GH#44417 cast to Series so we can use .iat below, which will be
# robust in case we
Expand All @@ -6393,10 +6390,10 @@ def astype(
for i, (col_name, col) in enumerate(self.items()):
cdt = dtype_ser.iat[i]
if isna(cdt):
res_col = col.copy(deep=copy)
res_col = col.copy(deep=False)
else:
try:
res_col = col.astype(dtype=cdt, copy=copy, errors=errors)
res_col = col.astype(dtype=cdt, errors=errors)
except ValueError as ex:
ex.args = (
f"{ex}: Error while type casting for column '{col_name}'",
Expand All @@ -6410,22 +6407,20 @@ def astype(
if isinstance(dtype, ExtensionDtype) and all(
arr.dtype == dtype for arr in self._mgr.arrays
):
return self.copy(deep=copy)
return self.copy(deep=False)
# GH 18099/22869: columnwise conversion to extension dtype
# GH 24704: self.items handles duplicate column names
results = [
ser.astype(dtype, copy=copy, errors=errors) for _, ser in self.items()
]
results = [ser.astype(dtype, errors=errors) for _, ser in self.items()]

else:
# else, only a single dtype is given
new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
new_data = self._mgr.astype(dtype=dtype, errors=errors)
res = self._constructor_from_mgr(new_data, axes=new_data.axes)
return res.__finalize__(self, method="astype")

# GH 33113: handle empty frame or series
if not results:
return self.copy(deep=None)
return self.copy(deep=False)

# GH 19920: retain column metadata after concat
result = concat(results, axis=1, copy=False)
Expand Down
Loading