diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index f1df86788ac44..7c30d53522ad9 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -132,6 +132,19 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False) -> Self: values, mask = cls._coerce_to_array(scalars, dtype=dtype, copy=copy) return cls(values, mask) + @classmethod + @doc(ExtensionArray._empty) + def _empty(cls, shape: Shape, dtype: ExtensionDtype): + values = np.empty(shape, dtype=dtype.type) + values.fill(cls._internal_fill_value) + mask = np.ones(shape, dtype=bool) + result = cls(values, mask) + if not isinstance(result, cls) or dtype != result.dtype: + raise NotImplementedError( + f"Default 'empty' implementation is invalid for dtype='{dtype}'" + ) + return result + @property def dtype(self) -> BaseMaskedDtype: raise AbstractMethodError(self) diff --git a/pandas/core/dtypes/base.py b/pandas/core/dtypes/base.py index 7c05ec1ba33a9..f0e55aa178ec0 100644 --- a/pandas/core/dtypes/base.py +++ b/pandas/core/dtypes/base.py @@ -211,7 +211,7 @@ def construct_array_type(cls) -> type_t[ExtensionArray]: """ raise AbstractMethodError(cls) - def empty(self, shape: Shape) -> type_t[ExtensionArray]: + def empty(self, shape: Shape) -> ExtensionArray: """ Construct an ExtensionArray of this dtype with the given shape.