diff --git a/narwhals/_pandas_like/dataframe.py b/narwhals/_pandas_like/dataframe.py index b9080322d..08bb88d58 100644 --- a/narwhals/_pandas_like/dataframe.py +++ b/narwhals/_pandas_like/dataframe.py @@ -698,9 +698,6 @@ def to_numpy(self, dtype: Any = None, copy: bool | None = None) -> Any: # pandas default differs from Polars, but cuDF default is True copy = self._implementation is Implementation.CUDF - if dtype is not None: - return self._native_frame.to_numpy(dtype=dtype, copy=copy) - df = self.with_columns( *[ self.__narwhals_namespace__() @@ -712,6 +709,9 @@ def to_numpy(self, dtype: Any = None, copy: bool | None = None) -> Any: ] )._native_frame + if dtype is not None: + return df.to_numpy(dtype=dtype, copy=copy) + # pandas return `object` dtype for nullable dtypes if dtype=None, # so we cast each Series to numpy and let numpy find a common dtype. # If there aren't any dtypes where `to_numpy()` is "broken" (i.e. it