Repository: modin-project/modin

Issue:
don't trigger axes computation in `pivot_table`
Modin already has the functionality of creating a dataframe with non-materialized indexes. We can try to extend this approach to `pivot_table`.


Discussion:

Resolving patch:
diff --git a/modin/core/dataframe/pandas/dataframe/dataframe.py b/modin/core/dataframe/pandas/dataframe/dataframe.py
--- a/modin/core/dataframe/pandas/dataframe/dataframe.py
+++ b/modin/core/dataframe/pandas/dataframe/dataframe.py
@@ -2686,13 +2686,17 @@ def broadcast_apply_full_axis(
             enumerate_partitions=enumerate_partitions,
             keep_partitioning=keep_partitioning,
         )
-        # Index objects for new object creation. This is shorter than if..else
-        kw = self.__make_init_labels_args(new_partitions, new_index, new_columns)
+        kw = {"row_lengths": None, "column_widths": None}
         if dtypes == "copy":
             kw["dtypes"] = self._dtypes
         elif dtypes is not None:
+            if new_columns is None:
+                (
+                    new_columns,
+                    kw["column_widths"],
+                ) = self._compute_axis_labels_and_lengths(1, new_partitions)
             kw["dtypes"] = pandas.Series(
-                [np.dtype(dtypes)] * len(kw["columns"]), index=kw["columns"]
+                [np.dtype(dtypes)] * len(new_columns), index=new_columns
             )
 
         if not keep_partitioning:
@@ -2719,7 +2723,9 @@ def broadcast_apply_full_axis(
                     and len(new_columns) == sum(self._column_widths_cache)
                 ):
                     kw["column_widths"] = self._column_widths_cache
-        result = self.__constructor__(new_partitions, **kw)
+        result = self.__constructor__(
+            new_partitions, index=new_index, columns=new_columns, **kw
+        )
         if sync_labels and new_index is not None:
             result.synchronize_labels(axis=0)
         if sync_labels and new_columns is not None:
diff --git a/modin/core/storage_formats/pandas/query_compiler.py b/modin/core/storage_formats/pandas/query_compiler.py
--- a/modin/core/storage_formats/pandas/query_compiler.py
+++ b/modin/core/storage_formats/pandas/query_compiler.py
@@ -3167,6 +3167,9 @@ def __convert_by(by):
             to_group = self.drop(columns=unique_keys)
 
         keys_columns = self.getitem_column_array(unique_keys)
+        len_values = len(values)
+        if len_values == 0:
+            len_values = len(self.columns.drop(unique_keys))
 
         def applyier(df, other):
             """
@@ -3200,6 +3203,11 @@ def applyier(df, other):
                 sort=sort,
             )
 
+            # if only one value is specified, removing level that maps
+            # columns from `values` to the actual values
+            if len(index) > 0 and len_values == 1 and result.columns.nlevels > 1:
+                result.columns = result.columns.droplevel(int(margins))
+
             # in that case Pandas transposes the result of `pivot_table`,
             # transposing it back to be consistent with column axis values along
             # different partitions
@@ -3218,14 +3226,6 @@ def applyier(df, other):
         if len(index) == 0 and len(columns) > 0:
             result = result.transpose()
 
-        if len(values) == 0:
-            values = self.columns.drop(unique_keys)
-
-        # if only one value is specified, removing level that maps
-        # columns from `values` to the actual values
-        if len(index) > 0 and len(values) == 1 and result.columns.nlevels > 1:
-            result.columns = result.columns.droplevel(int(margins))
-
         return result
 
     # Get_dummies


Test patch: