@@ -203,18 +203,32 @@ def __internal_pivot_table(
203
203
to_unstack .append (name )
204
204
table = agged .unstack (to_unstack )
205
205
206
- if not dropna :
207
- if isinstance (table .index , MultiIndex ):
208
- m = MultiIndex .from_arrays (
209
- cartesian_product (table .index .levels ), names = table .index .names
210
- )
211
- table = table .reindex (m , axis = 0 )
212
-
213
- if isinstance (table .columns , MultiIndex ):
214
- m = MultiIndex .from_arrays (
215
- cartesian_product (table .columns .levels ), names = table .columns .names
216
- )
217
- table = table .reindex (m , axis = 1 )
206
+ # BEGIN Issue #18030
207
+ # Commenting these lines in view of #18030.
208
+ # The cartesian product makes little sense and deprecation of this behaviour should be considered.
209
+ # It is unexpected that a pivot operation returns a larger index than is given.
210
+ # Secondly, this behaviour was never documented. The documentation says
211
+ #
212
+ # dropna:bool, default True
213
+ #
214
+ # Do not include columns whose entries are all NaN.
215
+ #
216
+ # However the code below creates rows.
217
+
218
+ # if not dropna:
219
+ # if isinstance(table.index, MultiIndex):
220
+ # m = MultiIndex.from_arrays(
221
+ # cartesian_product(table.index.levels), names=table.index.names
222
+ # )
223
+ # table = table.reindex(m, axis=0)
224
+ #
225
+ # if isinstance(table.columns, MultiIndex):
226
+ # m = MultiIndex.from_arrays(
227
+ # cartesian_product(table.columns.levels), names=table.columns.names
228
+ # )
229
+ # table = table.reindex(m, axis=1)
230
+
231
+ # END Issue #18030
218
232
219
233
if isinstance (table , ABCDataFrame ):
220
234
table = table .sort_index (axis = 1 )
0 commit comments