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: set_index on more than 1 column changes boolean values #46987
Comments
The issue arises from the implementation of In cpython - Which in turn effects sets and dictionaries This rises the question if this issue should be handled or not, This following example of code will give some more context into my original use case, which i believe shows that this behavior is not ideal. @simonjayhawkins - what do you think? I assume that we can create a special behavior for booleans (actually the same happens with |
A pandas index should be thought of as a hash map (e.g. a dictionary). With this mental model, it would be unexpected if two objects were equal but not treated as the same key in a hash map. I agree with the stance that this is undesired behavior, but I think it is undesired behavior of Python rather than pandas. I am concerned that going against how Python behaves will only lead to further issues or confusion. I am also surprised to find that NumPy also exhibits this behavior:
|
@rhshadrach - thanks! |
I think this needs more discussion; my current thought is that while this behavior is undesirable, modifying it may be more undesirable. Another example. Trying to index using a Boolean value is specifically handled by pandas, but float is not.
|
OK. Would gladly help to find more places in which we have this behavior / implement a fix |
Before opening another Issue I would like the following behaviour depends also on the same problem ( Creating a Pseudo-MultiIndex with tuples in an But an The problem described with that MWE is that after converting the
|
Hey @rhshadrach, |
I think I'm -1 here. You're asking pandas to differentiate two Python objects when Python itself does not.
It seems to me that this is going to lead to special casing and complexities in the pandas code that provide little value. |
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
set_index on more than 1 column may change the values of booleans to integers/floats.
this issue only happens if (0, 0.0, 1, 1.0) are found in the same column as (True/False).
Expected Behavior
set_index
should not change valuesInstalled Versions
INSTALLED VERSIONS
commit : 4bfe3d0
python : 3.8.7.final.0
python-bits : 64
OS : Darwin
OS-release : 20.4.0
Version : Darwin Kernel Version 20.4.0: Fri Mar 5 01:14:14 PST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.4.2
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 21.3.1
setuptools : 58.3.0
Cython : 0.29.28
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : 1.10.6
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.3.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.3.0
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.5.2
numba : 0.53.1
numexpr : 2.8.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 6.0.1
pyreadstat : None
pyxlsb : None
s3fs : 2022.02.0
scipy : 1.8.0
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: