Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of pandas.

  • [X] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np
df = pd.DataFrame({"A": ["10", ""], "B": ["one", "two"], "D": [1, 2]})
table = pd.pivot_table(df, values='D', index=['A', 'B'], aggfunc=np.sum, dropna=False)

Issue Description

df | | A | B | D | |---:|:----|:----|----:| | 0 | 10 | one | 1 | | 1 | | two | 2 |

table | | D | |:--------------|----:| | ('', 'one') | nan | | ('', 'two') | 2 | | ('10', 'one') | 1 | | ('10', 'two') | nan |"

Rows 1 and 4 are obviously redundant.

Expected Behavior

D
('', 'two') 2
('10', 'one') 1

Installed Versions

INSTALLED VERSIONS ------------------ commit : f3d4113052e3d09f3a2cf288a9f1dcd17ab113a1 python : 3.10.9.final.0 python-bits : 64 OS : Linux OS-release : 5.10.16.3-microsoft-standard-WSL2 Version : #1 SMP Fri Apr 2 22:23:49 UTC 2021 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.0.0.dev0+1541.gf3d4113052 numpy : 1.24.2 pytz : 2022.7.1 dateutil : 2.8.2 setuptools : 65.5.0 pip : 22.3.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : 0.9.0 xarray : None xlrd : None zstandard : None tzdata : None qtpy : None pyqt5 : None

Comment From: phofl

Hi, thanks for your report. This is independent of empty strings and I think this behaves as expected, but not sure

Comment From: alexey-buzuverov

Thanks for clarification. It simply takes all possible index permutations to make table rows when dropna=False.