API: Standard signature for to_numpy by TomAugspurger · Pull Request #24341 · pandas-dev/pandas (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we may be double copying. I'm not quite sure how to detect that. I'm not sure how to best handle this.

One option I considered is adding a method to the EA interface _to_numpy that returns (ndarray, did_copy). Then this could be written as

if is_extension_array_dtype(self.dtype): result, copied = self.array._to_numpy(dtype, copy)

if copy and not copied: return result

Do you think avoiding the double-copy is worth that complexity? Or perhaps there's a cleaner way I haven't thought of.