You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I create a 1 row dataframe with multiindex
I reindex on a single level, and I expect all values in the new index to be in the new dataframe.
instead, the same dataframe is returned.
the same happens with more than a single row.
If I use a 1d index, or apply to the columns, I get a 100 row/column dataframe as expected
Expected Behavior
expected_output = pd.DataFrame({"a":10, "b": range(100), "c": np.nan}).set_index(["a", "b"])
expected_output.loc[(10,2), "c"]=1
expected_output.head()
# c
# a b
# 10 0 NaN
# 1 NaN
# 2 1.0
# 3 NaN
# 4 NaN
Installed Versions
INSTALLED VERSIONS
------------------
commit : e86ed37
python : 3.11.5.final.0
python-bits : 64
OS : Darwin
OS-release : 23.5.0
Version : Darwin Kernel Version 23.5.0: Wed May 1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
Thanks for submitting this bug, I suppose that this might be an enhancement as reindex doesn't have the capability to fill up index values as well after reindexing. The documentation for reindex method says for the named argument level
Broadcast across a level, matching Index values on the passed MultiIndex level.
Because it matches values, thus it discards anything which is not 1-1 mapped on the index. The fill_value is only for the values to the indexes and not the index itself.
Sorry, I think I misunderstood the documentation. I expected the level argument to allow me to reindex on only a single level of a multiindex, where I pass a 1D index, and expect it to create the cartesian product of remaining index columns and my passed 1D index.
So to me the "broadcasting" was replicating the specified level values across all the remaining index columns.
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
I create a 1 row dataframe with multiindex
I reindex on a single level, and I expect all values in the new index to be in the new dataframe.
instead, the same dataframe is returned.
the same happens with more than a single row.
If I use a 1d index, or apply to the columns, I get a 100 row/column dataframe as expected
Expected Behavior
Installed Versions
pandas : 2.1.1
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: