Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df1 = pd.DataFrame(data=['a', 'b', 'c'])
df2 = pd.DataFrame(data=['b', 'a', 'c'])
hash1 = pd.util.hash_pandas_object(df1)
hash2 = pd.util.hash_pandas_object(df2)
print(f'hash1: {hash1} \n hash2: {hash2}')
# hash1: 0 14639053686158035780
# 1 3869563279212530728
# 2 393322362522515241
# dtype: uint64
# hash2: 0 6989536449337278821
# 1 7554402398462747209
# 2 393322362522515241
hash1_alt = pd.util.hash_pandas_object(df1, categorize=False)
hash2_alt = pd.util.hash_pandas_object(df2, categorize=False)
print(f'hash1: {hash1_alt} \n hash2: {hash2_alt}')
df1_n = pd.DataFrame(data=[1,2,3])
df2_n = pd.DataFrame(data=[2,1,3])
print(f'''hash1: {pd.util.hash_pandas_object(df1_n)}
hash2: {pd.util.hash_pandas_object(df2_n)}''')
Issue Description
I understand deterministic integer to mean, "the same input leads to the same output". However, simply changing the order of elements within an array already leads to different hashes for the same element. Is the idea instead that the exact same array will lead to the exact same hashes? If so that should be clarified in the documentation.
Expected Behavior
The same hashes appear, just in a different order
df1 = pd.DataFrame(data=['a', 'b', 'c'])
df2 = pd.DataFrame(data=['b', 'a', 'c'])
hash1 = pd.util.hash_pandas_object(df1)
hash2 = pd.util.hash_pandas_object(df2)
print(f'hash1: {hash1} \n hash2: {hash2}')
# hash1: 0 7554402398462747209
# 1 6989536449337278821
# 2 393322362522515241
# dtype: uint64
# hash2: 0 6989536449337278821
# 1 7554402398462747209
# 2 393322362522515241
Installed Versions
pandas : 2.1.1
numpy : 1.25.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3.1
Cython : 0.29.34
pytest : 7.4.2
hypothesis : None
sphinx : None
blosc : 1.11.1
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : 2023.3.0
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : 2.8.5
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : 1.2.3
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : None
tables : None
tabulate : None
xarray : 2023.8.0
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None