Skip to content

Commit b63e452

Browse files
author
Randolf Scholz
committed
1 parent 79ffc96 commit b63e452

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

pandas/core/reshape/pivot.py

+26-12
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,32 @@ def __internal_pivot_table(
203203
to_unstack.append(name)
204204
table = agged.unstack(to_unstack)
205205

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
218232

219233
if isinstance(table, ABCDataFrame):
220234
table = table.sort_index(axis=1)

0 commit comments

Comments
 (0)