From 0a8cca551ba8c43ea505c4a789d4d82070ca64ff Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 1 Jun 2020 09:26:07 +0200 Subject: [PATCH] BUG: fix BooleanArray.astype('string') (GH34110) --- pandas/core/arrays/boolean.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 6b7b282bfd940..5d791ffd20f01 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -370,11 +370,15 @@ def astype(self, dtype, copy: bool = True) -> ArrayLike: if incompatible type with an BooleanDtype, equivalent of same_kind casting """ + from pandas.core.arrays.string_ import StringDtype + dtype = pandas_dtype(dtype) if isinstance(dtype, BooleanDtype): values, mask = coerce_to_array(self, copy=copy) return BooleanArray(values, mask, copy=False) + elif isinstance(dtype, StringDtype): + return dtype.construct_array_type()._from_sequence(self, copy=False) if is_bool_dtype(dtype): # astype_nansafe converts np.nan to True