Skip to content

Fix errors='ignore' being ignored in astype #30324 #30670

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

Closed
wants to merge 13 commits into from
Closed
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5576,7 +5576,7 @@ def astype(self, dtype, copy: bool_t = True, errors: str = "raise"):
"""
if is_dict_like(dtype):
if self.ndim == 1: # i.e. Series
if len(dtype) > 1 or self.name not in dtype:
if len(dtype) > 1 or self.name not in dtype and errors == "raise":
raise KeyError(
"Only the Series name can be used for "
"the key in Series dtype mappings."
Expand All @@ -5585,7 +5585,7 @@ def astype(self, dtype, copy: bool_t = True, errors: str = "raise"):
return self.astype(new_type, copy, errors)

for col_name in dtype.keys():
if col_name not in self:
if col_name not in self and errors == "raise":
raise KeyError(
"Only a column name can be used for the "
"key in a dtype mappings argument."
Expand Down