diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 3693edbae7d95..a468752c94093 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -538,12 +538,14 @@ def to_native_types(self, na_rep="nan", quoting=None, **kwargs): result = to_native_types(self.values, na_rep=na_rep, quoting=quoting, **kwargs) return self.make_block(result) - @final def copy(self, deep: bool = True): """copy constructor""" values = self.values if deep: - values = values.copy() + # "K" -> retain 'order' where possible, can be significantly + # faster than the default. + # error: Too many arguments for "copy" of "ExtensionArray" + values = values.copy("K") # type: ignore[call-arg] return type(self)(values, placement=self._mgr_locs, ndim=self.ndim) # --------------------------------------------------------------------- @@ -1699,6 +1701,15 @@ def _unwrap_setitem_indexer(self, indexer): ) return indexer + def copy(self, deep: bool = True): + """copy constructor""" + values = self.values + if deep: + # The base class method passes order="K", which is not part of + # the EA API. + values = values.copy() + return type(self)(values, placement=self._mgr_locs, ndim=self.ndim) + @property def is_view(self) -> bool: """Extension arrays are never treated as views."""