-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: .duplicated() ignoring duplicates for MultiIndex #60236
Comments
Thanks for the report. The levels that you are setting are not compatible with the codes in the MultiIndex. The As such you wind up with a MultiIndex that has an invalid state, it is going to give you wrong answers. |
If manipulating the index in a way that creates duplicates makes these methods return invalid results, then what is the purpose of |
It's not that you are creating duplicates. You are disabling safety checks, and then passing invalid data. That allows the index to get into an invalid state.
Always pass |
That results in
That's, of course, to be expected but like I said, I need to perform a calculation that temporarily results in duplicate values. Hence the |
You cannot use Closing. |
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
Issue Description
Pandas does not detect multiindex duplicates that were created using
set_levels()
.MRE outputs:
Python debugger cuts out in
multi.py::duplicated()
and I think the final error is somewhere in autogenerated cython hashtable bindings here? I'm not sure what to do to debug from multi.py onward.I found #27035 (comment), that mentions missing preconditions check that might be related, but this is pure speculation on my part. Besides, tuples should be hashable.
Expected Behavior
Detect duplicates/non-uniqueness. MRE outputs:
Installed Versions
INSTALLED VERSIONS
commit : 3f7bc81
python : 3.12.7
python-bits : 64
OS : Linux
OS-release : 6.11.4-gentoo
Version : #1 SMP PREEMPT_DYNAMIC Tue Oct 22 20:38:14 CEST 2024
machine : x86_64
processor : AMD Ryzen 5 4500 6-Core Processor
byteorder : little
LC_ALL : None
LANG : en_IE.utf8
LOCALE : en_IE.UTF-8
pandas : 3.0.0.dev0+1654.g3f7bc81ae
numpy : 2.1.3
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : 2024.2
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: