-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: MultiIndex converts "\x00"
to ""
#46764
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
Comments
Thanks @andreareina for the report. Can you give the issue an informative title.
Tuples used in the Index constructor create a single level MultiIndex. Under the hood the MultiIndex values are stored as factorized codes so this could be where the discrepancy occurs. Further investigation and PRs welcome. |
Seems to be happening in Code excerpted (and modified to replace return values from dependencies) from pandas/pandas/core/algorithms.py Lines 524 to 565 in 4bfe3d0
import numpy as np
import pandas as pd
values = np.array(["", "\x00"], dtype=object)
size_hint = None
na_sentinel = -1
na_value = None
mask = None
# Excerpted from https://github.com/pandas-dev/pandas/blob/4bfe3d07b4858144c219b9346329027024102ab6/pandas/core/algorithms.py#L524-L565 (factorize_array)
# hash_klass, values = _get_data_algo(values)
hash_klass = pd._libs.hashtable.StringHashTable
table = hash_klass(size_hint or len(values))
uniques, codes = table.factorize(
values, na_sentinel=na_sentinel, na_value=na_value, mask=mask
)
print(repr(uniques)) #=> array([''], dtype=object)
# codes = ensure_platform_int(codes) |
Probably related to #34551? |
appears so. there is also a comment on that issue, #34551 (comment) regarding MultiIndex and comments regarding other methods that use the factorize algo for Null-character strings. can probably close this as duplicate. |
Closing as a duplicate of #34551 |
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
Null-character strings in tuples are converted to the empty string when used as an index.
Expected Behavior
The null-character string should be preserved.
Installed Versions
INSTALLED VERSIONS
commit : 4bfe3d0
python : 3.8.11.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-104-generic
Version : #118~18.04.1-Ubuntu SMP Thu Mar 3 13:53:15 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_SG.UTF-8
LOCALE : en_SG.UTF-8
pandas : 1.4.2
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 21.2.3
setuptools : 57.4.0
Cython : None
pytest : 5.4.3
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
markupsafe : 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 : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: