diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index c69e61c899600..d421b422f9989 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -557,6 +557,7 @@ Numeric Conversion ^^^^^^^^^^ - Bug in :meth:`DataFrame.astype` when called with ``str`` on unpickled array - the array might change in-place (:issue:`54654`) +- Bug in :meth:`DataFrame.astype` where ``errors="ignore"`` had no effect for extension types (:issue:`54654`) - Bug in :meth:`Series.convert_dtypes` not converting all NA column to ``null[pyarrow]`` (:issue:`55346`) - diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a1617934ccb29..90946b8d9b5f4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6659,7 +6659,9 @@ def astype( return self.copy(deep=copy) # GH 18099/22869: columnwise conversion to extension dtype # GH 24704: self.items handles duplicate column names - results = [ser.astype(dtype, copy=copy) for _, ser in self.items()] + results = [ + ser.astype(dtype, copy=copy, errors=errors) for _, ser in self.items() + ] else: # else, only a single dtype is given diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 7016350f85086..9e70a59932701 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -1475,6 +1475,13 @@ def test_astype_float_from_non_pyarrow_str(): tm.assert_series_equal(result, expected) +def test_astype_errors_ignore(): + # GH 55399 + expected = pd.DataFrame({"col": [17000000]}, dtype="int32[pyarrow]") + result = expected.astype("float[pyarrow]", errors="ignore") + tm.assert_frame_equal(result, expected) + + def test_to_numpy_with_defaults(data): # GH49973 result = data.to_numpy()