diff --git a/narwhals/_pandas_like/dataframe.py b/narwhals/_pandas_like/dataframe.py index a011781d9..d9035e4d4 100644 --- a/narwhals/_pandas_like/dataframe.py +++ b/narwhals/_pandas_like/dataframe.py @@ -866,7 +866,6 @@ def pivot( if aggregate_function is None: result = frame.pivot(columns=on, index=index, values=values_) - elif aggregate_function == "len": result = ( frame.groupby([*on, *index]) # type: ignore[misc] @@ -882,11 +881,9 @@ def pivot( columns=on, aggregate_function=aggregate_function, ) + # Put columns in the right order - if ( - sort_columns - and self._implementation is Implementation.CUDF # pragma: no cover - ): + if sort_columns and self._implementation is Implementation.CUDF: uniques = { col: sorted(self._native_frame[col].unique().to_arrow().to_pylist()) for col in on diff --git a/narwhals/_pandas_like/utils.py b/narwhals/_pandas_like/utils.py index 89a030981..f4f6962e0 100644 --- a/narwhals/_pandas_like/utils.py +++ b/narwhals/_pandas_like/utils.py @@ -781,7 +781,7 @@ def pivot_table( aggregate_function: str | None, ) -> Any: dtypes = import_dtypes_module(df._version) - if df._implementation is Implementation.CUDF: # pragma: no cover + if df._implementation is Implementation.CUDF: if any(x == dtypes.Categorical for x in df.schema.values()): msg = "`pivot` with Categoricals is not implemented for cuDF backend" raise NotImplementedError(msg)